//==============================================================================================
/**
 * @file	intro.c
 * @brief	ゲーム開始導入デモ
 * @author	watanabeさん(DP)
 * @author	mori akitoさん(GS) → hosaka genya(GS)
 * @date	2009.03.28 (GS)
 */
//==============================================================================================
#include "common.h"

#include "system/procsys.h"
#include "system/arc_util.h"
#include "msgdata/msg.naix"
#include "system/pm_str.h"
#include "system/pm_rtc.h"
#include "system/palanm.h"
#include "system/wipe.h"
#include "system/window.h"
#include "system/snd_tool.h"
#include "system/savedata.h"
#include "system/palanm.h"
#include "system/msg_ds_icon.h"
#include "system/gra_tool.h"
#include "system/brightness.h"
#include "poketool/monsno.h"
#include "field/game_init.h"
#include "system/main.h"
#include "system/gamestart.h"
#include "system/pmfprint.h"

#include "msgdata/msg_intro.h"

#include "intro_sys.h"

#include "intro.naix"

//================================================================
//================================================================
//
//
//
//
//
//================================================================
//----------------------------------
//定数宣言
//----------------------------------
// ＰＲＯＣメインシーケンス
enum {
	INTRO_SEQ_INIT = 0,
	INTRO_SEQ_MAIN,
	INTRO_SEQ_EXIT,

	INTRO_SEQ_SUBPROC_CALL,
	INTRO_SEQ_SUBPROC_WAIT,
	INTRO_SEQ_SUBPROC_END,
};


//----------------------------------
//型宣言
//----------------------------------

//----------------------------------
//定数宣言
//----------------------------------
//メッセージ関数動作指定定義
enum {
	A_BUTTON_WAIT = 0,
	A_BUTTON_NOWAIT,
};

//メッセージ関数シーケンスナンバー定義
enum{
	MSGSET = 0,
	MSGDRAW,
	MSGWAIT,
};

//メッセージ関数動作指定定義
enum {
	B_BUTTON_ENABLE = 0,
	B_BUTTON_DISABLE,
};

//リスト関数シーケンスナンバー定義
enum {
	LISTSET = 0,
	LISTSELECT,
};

//リストタイプ
typedef enum {
	LISTTYPE_YESNO = 0,
	LISTTYPE_MENU,
	LISTTYPE_NAME,
}INTRO_LISTTYPE;

//ガイド関数シーケンスナンバー定義
enum{
	GUIDESET = 0,
	GUIDEDISPON,
	GUIDEFADEIN,
	GUIDEWAIT,
	GUIDEFADEOUT,
	GUIDEEND,
};

//ガイドタイプ
typedef enum {
	GUIDETYPE_OPERA = 0,
	GUIDETYPE_GUIDE,
	GUIDETYPE_EXPLAIN,
	GUIDETYPE_OPERA_L,	// 左スペース8
}INTRO_GUIDETYPE;

//背景モード設定(MainDisp)
enum {
	BGTYPE_MAIN_NULL = 0,
	BGTYPE_MAIN_TUTORIAL0,
	BGTYPE_MAIN_TUTORIAL1,
	BGTYPE_MAIN_TUTORIAL2,
	BGTYPE_MAIN_TUTORIAL3,
	BGTYPE_MAIN_GUIDE,
	BGTYPE_MAIN_END,
};

//人物モード設定(MainDisp)
enum {
	BGTYPE_MPPL_NULL = 0,
	BGTYPE_MPPL_DOCTOR,
	BGTYPE_MPPL_HERO_0,
	BGTYPE_MPPL_HERO_1,
	BGTYPE_MPPL_HERO_2,
	BGTYPE_MPPL_HERO_3,
	BGTYPE_MPPL_HEROINE_0,
	BGTYPE_MPPL_HEROINE_1,
	BGTYPE_MPPL_HEROINE_2,
	BGTYPE_MPPL_HEROINE_3,
	BGTYPE_MPPL_RIVAL,
	BGTYPE_MPPL_POKEMON,
	BGTYPE_MPPL_END,
};

//背景モード設定(SubDisp)
enum {
	BGTYPE_SUB_NULL = 0,
	BGTYPE_SUB_TUTORIALBALL,
	BGTYPE_SUB_GUIDEBALL,
	BGTYPE_SUB_YESNO,
	BGTYPE_SUB_SEXSELECT,
	BGTYPE_SUB_END,
};

//背景画面ボタンモード（SubDisp)
enum {
	BGTYPE_SUBBTN_3 = 0,
	BGTYPE_SUBBTN_2_TATE,
	BGTYPE_SUBBTN_2_YOKO,
	BGTYPE_SUBBTN_YESNO,
};


//半透明フェード関数シーケンスナンバー定義
enum {
	ALPHAFADEINIT = 0,
	ALPHAFADEIN,
	ALPHAFADEOUT,
	ALPHAFADEEND,
};

//半透明フェードモード定義
enum {
	ALPHA_FADEIN = 0,
	ALPHA_FADEOUT,
};

//スクロールモード定義
enum {
	SCROLL_CENTER = 0,
	SCROLL_RIGHT,
	SCROLL_LEFT,
};

// 下画面カーソルモード
enum {
	BTNTYPE_3,			// 選択肢３つ
	BTNTYPE_2,			// 　　　２つ縦
	BTNTYPE_2_FEMALE,	// 　　　２つ縦
};

// 画面スクロール処理設定
enum{
	MOVE_TYPE_CENTER_RIGHT,
	MOVE_TYPE_RIGHT_CENTER,
};

enum {
	GUIDE_PRINT_POS_Y_CENTER = 0xFFFF,	///< 算出された座標を中心にする
	GUIDE_PRINT_SIZE_Y_AUTO = 0xFFFF,	///< 算出された座標を中心にする
};

#define INTRO_SYSFNTPLT_S_NUM	( 14 )			// ボタンテキスト
#define BUTTON_TEXT_PAL		( INTRO_SYSFNTPLT_S_NUM )

#define INTRO_BGM_FADE_OUT_SYNC ( 6 )	/// BGM切替時に前の曲がフェードする時間

//----------------------------------
//外部関数定義
//----------------------------------
extern void	Main_SetNextProc(FSOverlayID ov_id, const PROC_DATA * proc_data);

//----------------------------------
//関数宣言
//----------------------------------
PROC_RESULT Intro_Init( PROC * proc, int * seq );
PROC_RESULT Intro_Main( PROC * proc, int * seq );
PROC_RESULT Intro_Exit( PROC * proc, int * seq );

static void Intro_VBlank( void* work );

static void Intro_VramBankSet( INTRO_DEMO_WORK* wk );
static void Intro_VramBankRelease( INTRO_DEMO_WORK* wk );
static void Intro_MsgDataSet( INTRO_DEMO_WORK* wk );
static void Intro_MsgDataRelease( INTRO_DEMO_WORK* wk );

static void Intro_GraphicLoad( INTRO_DEMO_WORK* wk );
static void Intro_GraphicLoadSceneM( INTRO_DEMO_WORK* wk, int type );
static void Intro_GraphicLoadScenePPL( INTRO_DEMO_WORK* wk, int type1, int type2 );
static void Intro_GraphicLoadSceneS( INTRO_DEMO_WORK* wk, int type );
static void Intro_GraphicLoadSceneBTN( INTRO_DEMO_WORK* wk, int type );

static BOOL Intro_Seq_introduction( INTRO_DEMO_WORK * wk );
static BOOL Intro_GSSeq( INTRO_DEMO_WORK * wk );


static void Intro_ButtonCursorAppear( INTRO_DEMO_WORK *wk, int type );
static void Intro_ButtonInit( INTRO_CURSOR_WORK *cursor, int type );
static int  Intro_ButtonMain( INTRO_DEMO_WORK *wk, int type );

static void Intro_ButtonMsgDel( INTRO_DEMO_WORK *wk );
static void Intro_ButtonMsgPrint( INTRO_DEMO_WORK * wk, u32 msgID1, u32 msgID2, u32 msgID3, int max );
static u32  Intro_OhkidoMsgSet(void);


static BOOL Intro_BgMove( INTRO_DEMO_WORK *wk, int frame, int movetype );

static void MaleFemale_ColChange(INTRO_DEMO_WORK *wk, BOOL b_init );
static void MaleFmale_NoSelect( INTRO_DEMO_WORK* wk );
static int Intro_SelectSex( INTRO_DEMO_WORK *wk );
static void NameDecideBgSet( INTRO_DEMO_WORK *wk );
static void _intro_text_frame_clear( INTRO_DEMO_WORK *wk );

// タッチボタンモード
typedef enum {
	INTRO_BTN_TOUCH_MODE_DISABLE = 0,
	INTRO_BTN_TOUCH_MODE_ENABLE,
	INTRO_BTN_TOUCH_MODE_TOUCH,
	INTRO_BTN_TOUCH_MODE_RESET,
}INTRO_BTN_TOUCH_MODE;

static void _TouchButton_Print( INTRO_DEMO_WORK* wk );
static void _TouchButton_Clear( INTRO_DEMO_WORK* wk );
static void Intro_TouchButtonMode( INTRO_DEMO_WORK* wk, INTRO_BTN_TOUCH_MODE mode );
static BOOL Intro_IsTouchButtonPushing( INTRO_DEMO_WORK* wk );
static BOOL Intro_GetTouchButtonEnable( INTRO_DEMO_WORK* wk );
static BOOL Intro_WaitInput( INTRO_DEMO_WORK* wk, BOOL b_chcek_button );
static void _fuck_touch_to_decide( INTRO_DEMO_WORK* wk );


//----------------------------------
//マクロ宣言
//----------------------------------
#define KEYTRG( pattern )	( ( sys.trg & ( pattern ) ) == ( pattern ) )
#define KEYCNT( pattern )	( ( sys.cont & ( pattern ) ) == ( pattern ) )

#define FADE( pattern, col, heapID ) {						\
	WIPE_SYS_Start(	WIPE_PATTERN_WMS,pattern,pattern,col,	\
					WIPE_DEF_DIV,WIPE_DEF_SYNC,heapID);		\
}
#define FADE_MAINONLY( pattern, col, heapID ) {				\
	WIPE_SYS_Start(	WIPE_PATTERN_M,pattern,pattern,col,		\
					WIPE_DEF_DIV,WIPE_DEF_SYNC,heapID);		\
}
#define FADE_SUBONLY( pattern, col, heapID ) {				\
	WIPE_SYS_Start(	WIPE_PATTERN_S,pattern,pattern,col,		\
					WIPE_DEF_DIV,WIPE_DEF_SYNC,heapID);		\
}


#define FRAME_ON( frame )		{ GF_BGL_VisibleSet( frame, VISIBLE_ON ); }
#define FRAME_OFF( frame )		{ GF_BGL_VisibleSet( frame, VISIBLE_OFF ); }
#define FRAME_ALLOFF {				\
	FRAME_OFF( GF_BGL_FRAME0_M )	\
	FRAME_OFF( GF_BGL_FRAME1_M )	\
	FRAME_OFF( GF_BGL_FRAME2_M )	\
	FRAME_OFF( GF_BGL_FRAME3_M )	\
	FRAME_OFF( GF_BGL_FRAME0_S )	\
	FRAME_OFF( GF_BGL_FRAME1_S )	\
	FRAME_OFF( GF_BGL_FRAME2_S )	\
	FRAME_OFF( GF_BGL_FRAME3_S )	\
}

//ＢＧコントロール定数
#define INTRO_TEXT_M_FRAME	(GF_BGL_FRAME0_M)
#define INTRO_PPL1_M_FRAME	(GF_BGL_FRAME1_M)
#define INTRO_PPL2_M_FRAME	(GF_BGL_FRAME2_M)
#define INTRO_BACK_M_FRAME	(GF_BGL_FRAME3_M)

#define INTRO_TEXT_S_FRAME	(GF_BGL_FRAME0_S)
#define INTRO_PPL1_S_FRAME	(GF_BGL_FRAME1_S)
#define INTRO_PBTN_S_FRAME	(GF_BGL_FRAME2_S)
#define INTRO_BACK_S_FRAME	(GF_BGL_FRAME3_S)

//その他
#define INTRO_MONSNO ( MONSNO_MARIRU )

#define MSGSPD		( CONFIG_GetMsgPrintSpeed( wk->config ))
//=================================================================================================
//
// ＰＲＯＣ定義テーブル
//
//=================================================================================================
const PROC_DATA IntroProcData = {
	Intro_Init,
	Intro_Main,
	Intro_Exit,
	NO_OVERLAY_ID
};

extern PROC_RESULT IntroTV_Init( PROC * proc, int * seq );
extern PROC_RESULT IntroTV_Main( PROC * proc, int * seq );
extern PROC_RESULT IntroTV_Exit( PROC * proc, int * seq );

static const PROC_DATA IntroTVProcData = {
	IntroTV_Init,
	IntroTV_Main,
	IntroTV_Exit,
	NO_OVERLAY_ID
};

//================================================================
//==============================================================================
/**
 * @brief   ＰＲＯＣ初期化
 *
 * @param   proc
 * @param   seq
 *
 * @retval  PROC_RESULT
 */
//==============================================================================
PROC_RESULT Intro_Init(PROC * proc, int * seq)
{
	INTRO_DEMO_WORK * wk;
	int	heapID = HEAPID_INTRO;

	sys_CreateHeap( HEAPID_BASE_APP, heapID, 0x40000 );

	wk = PROC_AllocWork( proc, sizeof( INTRO_DEMO_WORK ), heapID );
	memset( wk, 0, sizeof( INTRO_DEMO_WORK ) );

	wk->heapID	= heapID;
	wk->sv		= ((MAINWORK *)PROC_GetParentWork( proc ))->savedata;
	wk->config	= SaveData_GetConfig( wk->sv );

	wk->subseq	= 0;
	wk->subnextseq = 0;
	wk->subproc	= NULL;
	wk->myname    = NameIn_ParamAllocMake( heapID, NAMEIN_MYNAME, 0, NAMEIN_PERSON_LENGTH, wk->config, NULL );
	wk->rivalname = NameIn_ParamAllocMake( heapID, NAMEIN_RIVALNAME, 0, NAMEIN_PERSON_LENGTH, wk->config, NULL );
	wk->gender_work = 0;

//	wk->maindisp_mode	= BGTYPE_MAIN_NULL;
//	wk->ppl1disp_mode	= BGTYPE_MPPL_NULL;
//	wk->ppl2disp_mode	= BGTYPE_MPPL_NULL;
//	wk->subdisp_mode	= BGTYPE_SUB_NULL;
	wk->wait			= 0;

	// メッセージ送りをタッチパネルで無効に
	MsgPrintTouchPanelFlagSet( MSG_TP_OFF );

	// タッチフォントをロード
	FontProc_LoadFont( FONT_TOUCH, wk->heapID );

	return	PROC_RES_FINISH;
}

//==============================================================================
/**
 * @brief   ＰＲＯＣメイン
 *
 * @param   proc
 * @param   seq
 *
 * @retval  PROC_RESULT
 */
//==============================================================================
PROC_RESULT Intro_Main(PROC * proc, int* seq)
{
	INTRO_DEMO_WORK * wk = PROC_GetWork( proc );
	PROC_RESULT result = PROC_RES_CONTINUE;

//	intro_obj_test(wk );

	switch( *seq ){
	// 画面初期化
	case INTRO_SEQ_INIT:
		WIPE_SetBrightness( WIPE_DISP_MAIN,WIPE_FADE_BLACK );
		WIPE_SetBrightness( WIPE_DISP_SUB,WIPE_FADE_BLACK );

		sys_VBlankFuncChange( NULL, NULL );	// VBlankセット
		sys_HBlankIntrSet( NULL,NULL );		// HBlankセット

		GF_Disp_GX_VisibleControlInit();
		GF_Disp_GXS_VisibleControlInit();
		GX_SetVisiblePlane(0);
		GXS_SetVisiblePlane(0);
		sys_KeyRepeatSpeedSet(4,8);

		Intro_VramBankSet( wk );
		Intro_MsgDataSet( wk );

		GF_BGL_ScrClear( wk->bgl, INTRO_TEXT_S_FRAME );

		// セルタクター初期化
		Intro_CellActInit( wk );
		Intro_CellActSet(wk);

		wk->p_yesno = LargeYesno_Create( wk->bgl, wk->awp[INTRO_OBJ_YESNO_CUR_S],
										 INTRO_PBTN_S_FRAME, INTRO_TEXT_S_FRAME, BUTTON_TEXT_PAL, wk->heapID );

		sys_VBlankFuncChange(Intro_VBlank,(void*)wk);
		GF_Disp_DispOn();

		*seq = INTRO_SEQ_MAIN;
		break;

	// メインループ
	case INTRO_SEQ_MAIN:
//		if( Intro_Seq_introduction( wk ) == TRUE ){

		_fuck_touch_to_decide( wk );

		if( Intro_GSSeq( wk ) == TRUE ){
			FADE( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID )
			*seq = INTRO_SEQ_EXIT;
		}
		if( wk->subproc != NULL ){
			FADE( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID )
			*seq = INTRO_SEQ_SUBPROC_CALL;
		}
		break;

	// 終了
	case INTRO_SEQ_EXIT:
		if(WIPE_SYS_EndCheck() == TRUE){
			LargeYesno_Delete( wk->p_yesno );
			Intro_CellActRerease( wk );
			Intro_MsgDataRelease( wk );
			Intro_VramBankRelease( wk );

			sys_VBlankFuncChange( NULL, NULL );

			result = PROC_RES_FINISH;
		}
		break;

	// サブＰＲＯＣ呼び出し
	case INTRO_SEQ_SUBPROC_CALL:
		if(WIPE_SYS_EndCheck() == TRUE){
			LargeYesno_Delete( wk->p_yesno );
			Intro_CellActRerease( wk );
			Intro_MsgDataRelease( wk );
			Intro_VramBankRelease( wk );

			sys_VBlankFuncChange( NULL, NULL );

			*seq = INTRO_SEQ_SUBPROC_WAIT;
		}
		break;

	// サブＰＲＯＣ終了待ち
	case INTRO_SEQ_SUBPROC_WAIT:
		if( ProcMain( wk->subproc ) == TRUE ){
			PROC_Delete( wk->subproc );
			wk->subproc = NULL;

			*seq = INTRO_SEQ_SUBPROC_END;
		}
		break;

	// サブＰＲＯＣより復帰
	case INTRO_SEQ_SUBPROC_END:

		*seq = INTRO_SEQ_INIT;
		break;
	}
	if(wk->subproc==NULL && wk->crp!=NULL){
		CATS_Draw( wk->crp );
	}
	return result;
}

//==============================================================================
/**
 * @brief   ＰＲＯＣ終了
 *
 * @param   proc
 * @param   seq
 *
 * @retval  PROC_RESULT
 */
//==============================================================================
PROC_RESULT Intro_Exit(PROC * proc, int * seq)
{
	INTRO_DEMO_WORK * wk = PROC_GetWork( proc );
	int heapID = wk->heapID;

	FontProc_UnloadFont( FONT_TOUCH );	// タッチフォント開放

	//パラメータ設定	主人公の名前＆性別
	MyStatus_SetMyNameFromString( SaveData_GetMyStatus(wk->sv), wk->myname->strbuf );
	MyStatus_SetMySex( SaveData_GetMyStatus(wk->sv), wk->myname->info );
	{
		MISC* misc = SaveData_GetMisc( wk->sv );

		MISC_SetRivalName( misc, wk->rivalname->strbuf );
	}

	NameIn_ParamDelete( wk->myname );
	NameIn_ParamDelete( wk->rivalname );

	PROC_FreeWork( proc );
	sys_DeleteHeap( heapID );

	Main_SetNextProc( OVERLAY_ID_GAMESTART, &AfterOpeningProcData );

	// メッセージ送りをタッチパネルで無効に
	MsgPrintTouchPanelFlagSet( MSG_TP_OFF );

	return	PROC_RES_FINISH;
}


//------------------------------------------------------------------
/**
 * @brief   ＶＢＬＡＮＫ関数
 *
 * @param   work		INTRO_DEMO_WORKのポインタ
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_VBlank(void* work)
{
	INTRO_DEMO_WORK* wk = work;

	GF_BGL_VBlankFunc(wk->bgl);

	CATS_RenderOamTrans();

}


//----------------------------------
//ローカル関数（タッチパネル関連）
//----------------------------------
#define BALLSW_CENTER_X	(128)
#define BALLSW_CENTER_Y	(100)
//------------------------------------------------------------------
/**
 * @brief   ボール演出
 *
 * @param   none
 *
 * @retval  BOOL	TRUEで演出終了
 */
//------------------------------------------------------------------
static BOOL TouchPanel_BallEffect( void )
{
	BOOL result = FALSE;
	u16 x,y;

	if(sys.tp_trg){
		if(( sys.tp_x < 256 )&&( sys.tp_y < 192 )){
			if( sys.tp_x < BALLSW_CENTER_X ){
				x = BALLSW_CENTER_X - sys.tp_x;
			} else {
				x = sys.tp_x - BALLSW_CENTER_X;
			}
			if( sys.tp_y < BALLSW_CENTER_Y ){
				y = BALLSW_CENTER_Y - sys.tp_y;
			} else {
				y = sys.tp_y - BALLSW_CENTER_Y;
			}
			if( ( x*x + y*y ) <= 16*16 ){
				result = TRUE;
			}
		}
	}
	return result;
}


//----------------------------------
//ＶＲＡＭ設定
//----------------------------------
#define INTRO_NULL_PALETTE	( 0x0000 )		//ＢＧバックグラウンドパレット
#define PALSIZE				( 2*16 )

// パレット設定(メイン画面)
#define INTRO_BACKPLT_M_NUM		( 0 )			//通常背景（以下３本分データセット）
#define INTRO_TUTPLT_M_NUM		( 1 )			//チュートリアル背景
#define INTRO_GUIDEPLT_M_NUM	( 2 )			//ぼうけんガイド背景
#define INTRO_MWINPLT_M_NUM		( 3 )			//システムメニューウインドウ
#define INTRO_TWINPLT_M_NUM		( 4 )			//会話ウインドウ
#define	INTRO_SYSFNTPLT_M_NUM	( 5 )			//システムビットマップ
#define	INTRO_TKFNTPLT_M_NUM	( 6 )			//会話ビットマップ
#define	INTRO_PPL1PLT_M_NUM		( 7 )			//人物ＢＧ１
#define	INTRO_PPL2PLT_M_NUM		( 8 )			//人物ＢＧ２
#define	INTRO_PPLNULLPLT_M_NUM	( 9 )			//人物エフェクト

// パレット設定(サブ画面)
#define INTRO_BACKPLT_S_NUM		( 0 )			//通常背景（以下５本分データセット）
#define INTRO_BALLPLT_S_NUM		( 1 )			//ボール背景
#define INTRO_GUIDEPLT_S_NUM	( 2 )			//ぼうけんガイド背景
#define INTRO_TUTPLT_S_NUM		( 3 )			//チュートリアル背景
#define INTRO_TUTYNPLT_S_NUM	( 4 )			//チュートリアル「はい・いいえ」背景
#define	INTRO_BTNYNPLT_S_NUM	( 5 )			//ボタン「はい・いいえ」（以下２本分データセット）
#define	INTRO_BTNYNPLT2_S_NUM	( 6 )			//ボタン「はい・いいえ」
#define	INTRO_BTNBALLPLT_S_NUM	( 7 )			//ボタンボール（以下３本分データセット）
#define	INTRO_BTNBALLPLT1_S_NUM	( 8 )			//ボタンボール
#define	INTRO_BTNBALLPLT2_S_NUM	( 9 )			//ボタンボール
#define	INTRO_PPL1PLT_S_NUM		( 10 )			//人物ＢＧ１
#define	INTRO_PPL2PLT_S_NUM		( 11 )			//人物ＢＧ２
#define	INTRO_PPLNULLPLT_S_NUM	( 10 )			//人物エフェクト
#define INTRO_SUBDISP_CURSOR	( 10 )			// ボタンカーソル用

// 会話ウィンドウキャラ（window.h参照）
#define INTRO_TWINCHR_SIZ	( TALK_WIN_CGX_SIZ )
#define INTRO_TWINCHR_NUM	( 0x400-INTRO_TWINCHR_SIZ )

// メニューウィンドウキャラ（window.h参照）
#define INTRO_MWINCHR_SIZ	( MENU_WIN_CGX_SIZ )
#define INTRO_MWINCHR_NUM	( INTRO_TWINCHR_NUM - INTRO_MWINCHR_SIZ )

// システムで使用されているキャラクター開始位置
#define INTRO_TEXTSYSCHAR_END	( INTRO_MWINCHR_NUM )

#define BGCONTSET( frame, scr, cgx ){									\
	header.screenBase	= scr;											\
	header.charBase		= cgx;											\
	GF_BGL_BGControlSet( wk->bgl, frame, &header, GF_BGL_MODE_TEXT );	\
	GF_BGL_ScrClear( wk->bgl, frame );									\
}

//------------------------------------------------------------------
/**
 * @brief   VRAM BANK設定
 *
 * @param   wk		INTRO_DEMO_WORK
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_VramBankSet( INTRO_DEMO_WORK* wk )
{
	{ //ＶＲＡＭ設定
		GF_BGL_DISPVRAM vramSetTable = {
			GX_VRAM_BG_128_A,				// メイン2DエンジンのBG
			GX_VRAM_BGEXTPLTT_NONE,			// メイン2DエンジンのBG拡張パレット

			GX_VRAM_SUB_BG_128_C,			// サブ2DエンジンのBG
			GX_VRAM_SUB_BGEXTPLTT_NONE,		// サブ2DエンジンのBG拡張パレット

			GX_VRAM_OBJ_128_B,				// メイン2DエンジンのOBJ
			GX_VRAM_OBJEXTPLTT_NONE,		// メイン2DエンジンのOBJ拡張パレット

			GX_VRAM_SUB_OBJ_16_I,			// サブ2DエンジンのOBJ
			GX_VRAM_SUB_OBJEXTPLTT_NONE,	// サブ2DエンジンのOBJ拡張パレット

			GX_VRAM_TEX_NONE,				// テクスチャイメージスロット
			GX_VRAM_TEXPLTT_NONE			// テクスチャパレットスロット
		};
		GF_Disp_SetBank( &vramSetTable );
	}

	{ //ＢＧライブラリ用メモリ確保
		wk->bgl = GF_BGL_BglIniAlloc(wk->heapID);
	}

	{ // ＢＧシステム設定
		GF_BGL_SYS_HEADER BGsys_data = {
			GX_DISPMODE_GRAPHICS,GX_BGMODE_0,GX_BGMODE_0,GX_BG0_AS_2D
		};
		GF_BGL_InitBG( &BGsys_data );
	}
	{ // メインＢＧシステム設定
		GF_BGL_BGCNT_HEADER header = {	0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
										0, 0, GX_BG_EXTPLTT_01, 1, 0, 0, FALSE };
		// テキストＢＧ設定(BG0)
		BGCONTSET( INTRO_TEXT_M_FRAME, GX_BG_SCRBASE_0x7800, GX_BG_CHARBASE_0x18000 )
		// 人物１ＢＧ設定(BG1)
		BGCONTSET( INTRO_PPL1_M_FRAME, GX_BG_SCRBASE_0x7000, GX_BG_CHARBASE_0x14000 )
		// 人物２ＢＧ設定(BG2)
		BGCONTSET( INTRO_PPL2_M_FRAME, GX_BG_SCRBASE_0x6800, GX_BG_CHARBASE_0x10000 )
		// 背景ＢＧ設定(BG3)
		BGCONTSET( INTRO_BACK_M_FRAME, GX_BG_SCRBASE_0x6000, GX_BG_CHARBASE_0x0c000 )

		//メッセージウインドウキャラ＆パレット読み込み（ウインドウ外側）
		TalkWinGraphicSet(	wk->bgl, INTRO_TEXT_M_FRAME, INTRO_TWINCHR_NUM, INTRO_TWINPLT_M_NUM,
							0, wk->heapID);
		//メニューウインドウキャラ＆パレット読み込み（ウインドウ外側）
		MenuWinGraphicSet(	wk->bgl,INTRO_TEXT_M_FRAME, INTRO_MWINCHR_NUM,INTRO_MWINPLT_M_NUM,
							0,wk->heapID);
		//フォントパレット読み込み（システム）
		SystemFontPaletteLoad( PALTYPE_MAIN_BG, INTRO_SYSFNTPLT_M_NUM*PALSIZE, wk->heapID );


		//フォントパレット読み込み（会話）
		TalkFontPaletteLoad( PALTYPE_MAIN_BG, INTRO_TKFNTPLT_M_NUM*PALSIZE, wk->heapID );
	}
	{ // サブＢＧシステム設定
		GF_BGL_BGCNT_HEADER header = {	0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
										0, 0, GX_BG_EXTPLTT_01, 0, 0, 0, FALSE };
		// テキストＢＧ設定(BG0)
		BGCONTSET( INTRO_TEXT_S_FRAME, GX_BG_SCRBASE_0x7800, GX_BG_CHARBASE_0x18000 )
		// はい・いいえＢＧ設定(BG1)
		BGCONTSET( INTRO_PPL1_S_FRAME, GX_BG_SCRBASE_0x7000, GX_BG_CHARBASE_0x14000 )
		// ボールＢＧ設定(BG2)
		BGCONTSET( INTRO_PBTN_S_FRAME, GX_BG_SCRBASE_0x6800, GX_BG_CHARBASE_0x10000 )
		// 背景ＢＧ設定(BG3)
		BGCONTSET( INTRO_BACK_S_FRAME, GX_BG_SCRBASE_0x6000, GX_BG_CHARBASE_0x0c000 )

		// 背景BGのプライオリティを下げる
		GF_BGL_PrioritySet( INTRO_BACK_S_FRAME, 3 );

		//フォントパレット読み込み（システム）
		SystemFontPaletteLoad( PALTYPE_SUB_BG, INTRO_SYSFNTPLT_S_NUM*PALSIZE, wk->heapID );

	}

	// テキスト面の０キャラをクリア
	GF_BGL_ClearCharSet( INTRO_TEXT_S_FRAME, 32, 0, wk->heapID );

	FRAME_ALLOFF
	Intro_GraphicLoad( wk );
	wk->alphafadeseq = ALPHAFADEINIT;
}

//------------------------------------------------------------------
/**
 * @brief   BGL設定解放
 *
 * @param   wk		INTRO_DEMO_WORK
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_VramBankRelease( INTRO_DEMO_WORK* wk )
{
	FRAME_ALLOFF

	GF_BGL_BGControlExit( wk->bgl, INTRO_TEXT_M_FRAME );
	GF_BGL_BGControlExit( wk->bgl, INTRO_PPL1_M_FRAME );
	GF_BGL_BGControlExit( wk->bgl, INTRO_PPL2_M_FRAME );
	GF_BGL_BGControlExit( wk->bgl, INTRO_BACK_M_FRAME );

	GF_BGL_BGControlExit( wk->bgl, INTRO_TEXT_S_FRAME );
	GF_BGL_BGControlExit( wk->bgl, INTRO_PPL1_S_FRAME );
	GF_BGL_BGControlExit( wk->bgl, INTRO_PBTN_S_FRAME );
	GF_BGL_BGControlExit( wk->bgl, INTRO_BACK_S_FRAME );

	sys_FreeMemoryEz( wk->bgl );
}


//------------------------------------------------------------------
/**
 * @brief   メッセージ設定
 *
 * @param   wk		INTRO_DEMO_WORK
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_MsgDataSet( INTRO_DEMO_WORK* wk )
{
	//メッセージデータ読み込み
	wk->msgman = MSGMAN_Create(MSGMAN_TYPE_DIRECT,ARC_MSG,NARC_msg_intro_dat,wk->heapID );
	//メッセージ表示システム初期化
	MSG_PrintInit();
	wk->msgicon = MSG_DsIconFlashAdd( NULL, MSG_DSI_MAINDISP, INTRO_TKFNTPLT_M_NUM, wk->heapID );
	wk->wordset = WORDSET_Create( wk->heapID );

	wk->msgseq		= MSGSET;
	wk->guideseq	= GUIDESET;
	wk->listseq		= LISTSET;
}

//------------------------------------------------------------------
/**
 * @brief   メッセージ解放
 *
 * @param   wk		INTRO_DEMO_WORK
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_MsgDataRelease( INTRO_DEMO_WORK* wk )
{
	WORDSET_Delete( wk->wordset );
//	MSG_DsIconFlashReq( wk->msgicon, MSG_DSI_REQ_FREE );
	MSG_DsIconFlashDelete( wk->msgicon );
	//メッセージデータ破棄
	MSGMAN_Delete(wk->msgman);
}


//----------------------------------
//半透明フェードインアウト（ＢＧ０，１，２に対して。ＢＧ３面（背景）を対象にする）
//----------------------------------
#define ALPHASET( plane, side ){														\
	if( side == 0 ){																	\
		G2_SetBlendAlpha(	plane,														\
			GX_BLEND_PLANEMASK_BG1|GX_BLEND_PLANEMASK_BG2|GX_BLEND_PLANEMASK_BG3,		\
			wk->alphaev1, wk->alphaev2 );												\
	} else {																			\
		G2S_SetBlendAlpha(	plane,														\
			GX_BLEND_PLANEMASK_BG1|GX_BLEND_PLANEMASK_BG2|GX_BLEND_PLANEMASK_BG3,		\
			wk->alphaev1, wk->alphaev2 );												\
	}																					\
}

//------------------------------------------------------------------
/**
 * @brief   半透明フェードインアウト（ＢＧ０，１，２に対して。ＢＧ３面（背景）を対象にする）
 *
 * @param   wk		INTRO_DEMO_WORK
 * @param   frame	BG面
 * @param   type	ALPHA_FADEIN or ALPHA_FADEOUT
 *
 * @retval  BOOL	フェードイン処理が終了したらTRUE
 */
//------------------------------------------------------------------
#define ALPHA_FRAME_OBJ_M (101)
#define ALPHA_FRAME_OBJ_S (102)
static BOOL Intro_AlphaFade( INTRO_DEMO_WORK * wk,int frame, int type )
{
	BOOL result = FALSE;
	GXBlendPlaneMask plane1;
	int dispside;

	switch( frame ){
	default:
	case GF_BGL_FRAME0_M:
		plane1 = GX_BLEND_PLANEMASK_BG0;
		dispside = 0;
		break;
	case GF_BGL_FRAME1_M:
		plane1 = GX_BLEND_PLANEMASK_BG1;
		dispside = 0;
		break;
	case GF_BGL_FRAME2_M:
		plane1 = GX_BLEND_PLANEMASK_BG2;
		dispside = 0;
		break;
	case GF_BGL_FRAME0_S:
		plane1 = GX_BLEND_PLANEMASK_BG0;
		dispside = 1;
		break;
	case GF_BGL_FRAME1_S:
		plane1 = GX_BLEND_PLANEMASK_BG1;
		dispside = 1;
		break;
	case GF_BGL_FRAME2_S:
		plane1 = GX_BLEND_PLANEMASK_BG2;
		dispside = 1;
		break;
	case ALPHA_FRAME_OBJ_M:
		plane1 = GX_BLEND_PLANEMASK_OBJ;
		dispside = 0;
		break;
	case ALPHA_FRAME_OBJ_S:
		plane1 = GX_BLEND_PLANEMASK_OBJ;
		dispside = 1;
		break;
	}
	switch( wk->alphafadeseq ){
	case ALPHAFADEINIT:
		if( type == ALPHA_FADEIN ){
			wk->alphaev1 = 0;
			wk->alphaev2 = 16;
			wk->alphafadeseq = ALPHAFADEIN;
			ALPHASET( plane1, dispside )
			if( frame == ALPHA_FRAME_OBJ_M ) {
				GF_Disp_GX_VisibleControl(  GX_PLANEMASK_OBJ, VISIBLE_ON );		// MAIN DISP OBJ
			}else if( frame == ALPHA_FRAME_OBJ_S ) {
				GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );		// SUB DISP OBJ
			}else{
				FRAME_ON( frame )
			}
		} else {
			wk->alphaev1 = 16;
			wk->alphaev2 = 0;
			wk->alphafadeseq = ALPHAFADEOUT;
		}
		break;
	case ALPHAFADEIN:
		if( wk->alphaev2 ){
			wk->alphaev1++;
			wk->alphaev2--;
			ALPHASET( plane1, dispside )
		} else {
			wk->alphafadeseq = ALPHAFADEEND;
		}
		break;

	case ALPHAFADEOUT:
		if( wk->alphaev1 ){
			wk->alphaev1--;
			wk->alphaev2++;
			ALPHASET( plane1, dispside )
		} else {
			wk->alphafadeseq = ALPHAFADEEND;

			if( frame == ALPHA_FRAME_OBJ_M ) {
				GF_Disp_GX_VisibleControl(  GX_PLANEMASK_OBJ, VISIBLE_OFF );	// MAIN DISP OBJ
			}else if( frame == ALPHA_FRAME_OBJ_S ) {
				GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_OFF );	// SUB DISP OBJ
			}else{
				FRAME_OFF( frame )
			}
		}
		break;

	case ALPHAFADEEND:
		G2_BlendNone();
		G2S_BlendNone();
		wk->alphafadeseq = ALPHAFADEINIT;
		result = TRUE;
		break;
	}
	return result;
}

//------------------------------------------------------------------
/**
 * @brief   簡易ウェイト
 *
 * @param   wk		INTRO_DEMO_WORK
 * @param   wait	指定ウェイト
 *
 * @retval  BOOL	TRUEで終了
 */
//------------------------------------------------------------------
static BOOL Intro_Wait( INTRO_DEMO_WORK * wk, int wait )
{
	if( wk->wait < wait ){
		wk->wait++;
		return FALSE;
	} else {
		wk->wait = 0;
		return TRUE;
	}
}

//------------------------------------------------------------------
/**
 * @brief   ＢＧスクリーンパレット変更
 *
 * @param   wk		INTRO_DEMO_WORK
 * @param   frame	BG面
 * @param   pal		パレット列番号
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_BGscrPalChange( INTRO_DEMO_WORK * wk, int frame, int pal )
{
	GF_BGL_ScrPalChange( wk->bgl, frame, 0, 0, 32, 24, pal );
	GF_BGL_LoadScreenReq( wk->bgl, frame );
}

//----------------------------------
//ＢＭＰウインドウ設定
//----------------------------------
#define INTRO_STRBUF_SIZE		(0x400)	//メッセージバッファサイズ

#define DOTSIZE					(8)

// メッセージウィンドウ（fldbmp.h参照、ＣＧＸ以外フィールドと同じ：コメントは数値）
#define	INTRO_MSG_WIN_PX		(2)
#define	INTRO_MSG_WIN_PY		(19)
#define	INTRO_MSG_WIN_SX		(27)
#define	INTRO_MSG_WIN_SY		(4)
#define	INTRO_MSG_WIN_PAL		(INTRO_TKFNTPLT_M_NUM)
#define	INTRO_MSG_WIN_CGX		(INTRO_TEXTSYSCHAR_END-(INTRO_MSG_WIN_SX*INTRO_MSG_WIN_SY))

// はい/いいえウィンドウ（fldbmp.h参照、ＣＧＸ以外フィールドと同じ：コメントは数値）
#define	INTRO_YESNO_WIN_PX		(2)
#define	INTRO_YESNO_WIN_PY		(3)
#define	INTRO_YESNO_WIN_SX		(6)
#define	INTRO_YESNO_WIN_SY		(4)
#define	INTRO_YESNO_WIN_PAL		(INTRO_SYSFNTPLT_M_NUM)
#define	INTRO_YESNO_WIN_CGX		(INTRO_MSG_WIN_CGX-(INTRO_YESNO_WIN_SX*INTRO_YESNO_WIN_SY))

// メインメニューウィンドウ
#define	INTRO_MENU_WIN_PX		(1)
#define	INTRO_MENU_WIN_PY		(3)
#define	INTRO_MENU_WIN_SX		(16)
#define	INTRO_MENU_WIN_SY		(6)
#define	INTRO_MENU_WIN_PAL		(INTRO_SYSFNTPLT_M_NUM)
#define	INTRO_MENU_WIN_CGX		(INTRO_MSG_WIN_CGX-(INTRO_MENU_WIN_SX*INTRO_MENU_WIN_SY))

// 名前リストウィンドウ
#define	INTRO_NAME_WIN_PX		(2)
#define	INTRO_NAME_WIN_PY		(3)
#define	INTRO_NAME_WIN_SX		(14)
#define	INTRO_NAME_WIN_SY		(10)
#define	INTRO_NAME_WIN_PAL		(INTRO_SYSFNTPLT_M_NUM)
#define	INTRO_NAME_WIN_CGX		(INTRO_MSG_WIN_CGX-(INTRO_NAME_WIN_SX*INTRO_NAME_WIN_SY))

// オペレーションウィンドウ
#define	INTRO_OPERA_WIN_PX		(4)
#define	INTRO_OPERA_WIN_PY		(0)
#define	INTRO_OPERA_WIN_SX		(24)
#define	INTRO_OPERA_WIN_SY		(24)
#define	INTRO_OPERA_WIN_PAL		(INTRO_SYSFNTPLT_M_NUM)
#define	INTRO_OPERA_WIN_CGX		(INTRO_MSG_WIN_CGX-(INTRO_OPERA_WIN_SX*INTRO_OPERA_WIN_SY))

// ガイドウィンドウ
#define	INTRO_GUIDE_WIN_PX		(4)
#define	INTRO_GUIDE_WIN_PY		(0)
#define	INTRO_GUIDE_WIN_SX		(24)
#define	INTRO_GUIDE_WIN_SY		(24)
#define	INTRO_GUIDE_WIN_PAL		(INTRO_SYSFNTPLT_M_NUM)
#define	INTRO_GUIDE_WIN_CGX		(INTRO_MSG_WIN_CGX-(INTRO_GUIDE_WIN_SX*INTRO_GUIDE_WIN_SY))

//ビットマップリスト構造体
typedef struct INTRO_BMPLIST_tag
{
	u32 msgID;
	u32 retID;
}INTRO_BMPLIST_TBL;

static const BMPWIN_DAT msg_windata = {
	INTRO_TEXT_M_FRAME,INTRO_MSG_WIN_PX,INTRO_MSG_WIN_PY,
	INTRO_MSG_WIN_SX,INTRO_MSG_WIN_SY,INTRO_MSG_WIN_PAL,INTRO_MSG_WIN_CGX
};
static const BMPWIN_DAT yesno_windata = {
	INTRO_TEXT_M_FRAME,INTRO_YESNO_WIN_PX,INTRO_YESNO_WIN_PY,
	INTRO_YESNO_WIN_SX,INTRO_YESNO_WIN_SY,INTRO_YESNO_WIN_PAL,INTRO_YESNO_WIN_CGX
};
static const BMPWIN_DAT menu_windata = {
	INTRO_TEXT_M_FRAME,INTRO_MENU_WIN_PX,INTRO_MENU_WIN_PY,
	INTRO_MENU_WIN_SX,INTRO_MENU_WIN_SY,INTRO_MENU_WIN_PAL,INTRO_MENU_WIN_CGX
};
static const BMPWIN_DAT name_windata = {
	INTRO_TEXT_M_FRAME,INTRO_NAME_WIN_PX,INTRO_NAME_WIN_PY,
	INTRO_NAME_WIN_SX,INTRO_NAME_WIN_SY,INTRO_NAME_WIN_PAL,INTRO_NAME_WIN_CGX
};
static const BMPWIN_DAT opera_windata = {
	INTRO_TEXT_M_FRAME,INTRO_OPERA_WIN_PX,INTRO_OPERA_WIN_PY,
	INTRO_OPERA_WIN_SX,INTRO_OPERA_WIN_SY,INTRO_OPERA_WIN_PAL,INTRO_OPERA_WIN_CGX
};
static const BMPWIN_DAT guide_windata = {
	INTRO_TEXT_M_FRAME,INTRO_GUIDE_WIN_PX,INTRO_GUIDE_WIN_PY,
	INTRO_GUIDE_WIN_SX,INTRO_GUIDE_WIN_SY,INTRO_GUIDE_WIN_PAL,INTRO_GUIDE_WIN_CGX
};

static const BMPLIST_HEADER listheader_default = {
	NULL,NULL,NULL,NULL,0,0,0,12,0,0,FBMP_COL_BLACK,FBMP_COL_WHITE,FBMP_COL_BLK_SDW,
	0,16,BMPLIST_NO_SKIP,FONT_SYSTEM,0
};

// ボタンの上に乗せるメッセージ（３個版・２個版）
#define BUTTON3_TEXT_X	(  7 )
#define BUTTON3_TEXT_W	( 18 )
#define BUTTON3_TEXT_H	(  3 )
#define BUTTON3_TEXT_Y1	(  3 )
#define BUTTON3_TEXT_Y2	( 10 )
#define BUTTON3_TEXT_Y3	( 17 )

#define BUTTON3_TEXT_CGX1	( 1 )
#define BUTTON3_TEXT_CGX2	( BUTTON3_TEXT_CGX1+(BUTTON3_TEXT_W*BUTTON3_TEXT_H) )
#define BUTTON3_TEXT_CGX3	( BUTTON3_TEXT_CGX2+(BUTTON3_TEXT_W*BUTTON3_TEXT_H) )
#define BUTTON_CGX_MAX_S ( BUTTON3_TEXT_CGX3+(BUTTON3_TEXT_W*BUTTON3_TEXT_H) )	// 下画面ボタンに使うCGX最大値


#define BUTTON2_TEXT_X	(  2 )
#define BUTTON2_TEXT_W	( 13 )
#define BUTTON2_TEXT_H	(  3 )
#define BUTTON2_TEXT_Y1	(  6 )
#define BUTTON2_TEXT_Y2	( 16 )

#define BUTTON2_TEXT_CGX1	( 1 )
#define BUTTON2_TEXT_CGX2	( BUTTON3_TEXT_W*BUTTON3_TEXT_H )

// ボタン上メッセージBMPWIN定義
static const BMPWIN_DAT buttonmsg_windata[][3] = {
	{
		{INTRO_TEXT_S_FRAME,BUTTON2_TEXT_X,BUTTON2_TEXT_Y1,
			BUTTON2_TEXT_W,BUTTON2_TEXT_H, BUTTON_TEXT_PAL, BUTTON2_TEXT_CGX1 },
		{INTRO_TEXT_S_FRAME,BUTTON2_TEXT_X,BUTTON2_TEXT_Y2,
			BUTTON2_TEXT_W,BUTTON2_TEXT_H, BUTTON_TEXT_PAL, BUTTON2_TEXT_CGX2 },
	},
	{
		{INTRO_TEXT_S_FRAME,BUTTON3_TEXT_X,BUTTON3_TEXT_Y1,
			BUTTON3_TEXT_W,BUTTON3_TEXT_H,BUTTON_TEXT_PAL,BUTTON3_TEXT_CGX1 },
		{INTRO_TEXT_S_FRAME,BUTTON3_TEXT_X,BUTTON3_TEXT_Y2,
			BUTTON3_TEXT_W,BUTTON3_TEXT_H,BUTTON_TEXT_PAL,BUTTON3_TEXT_CGX2 },
		{INTRO_TEXT_S_FRAME,BUTTON3_TEXT_X,BUTTON3_TEXT_Y3,
			BUTTON3_TEXT_W,BUTTON3_TEXT_H,BUTTON_TEXT_PAL,BUTTON3_TEXT_CGX3 },
	}
};

//--------------------------------------------------------------
///	タッチボタン
//==============================================================
enum {
	BTN_TOUCH_SX  = 7,
	BTN_TOUCH_SY  = 2,
	BTN_TOUCH_PX  = 25,
	BTN_TOUCH_PY  = 20,
	BTN_TOUCH_OBJ_SX  = 11,
	BTN_TOUCH_OBJ_SY  = 6,
	BTN_TOUCH_CGX  = BUTTON_CGX_MAX_S,
};

static const BMPWIN_DAT touch_button_msg_windata = {
	INTRO_TEXT_S_FRAME, BTN_TOUCH_PX, BTN_TOUCH_PY, BTN_TOUCH_SX, BTN_TOUCH_SY, BUTTON_TEXT_PAL, BTN_TOUCH_CGX
};

static const INTRO_BMPLIST_TBL yesno_list[] = {
	{msg_opening_24,1},{msg_opening_25,2}
};
static const INTRO_BMPLIST_TBL menu_list[] = {
	{msg_opening_21,1},{msg_opening_22,2},{msg_opening_23,3}
};
static const INTRO_BMPLIST_TBL name_list_d[] = {
	{msg_opening_26,1},{msg_opening_27,2},{msg_opening_28,3},{msg_opening_29,4},{msg_opening_30,5}
};
static const INTRO_BMPLIST_TBL name_list_p[] = {
	{msg_opening_26,1},{msg_opening_31,2},{msg_opening_32,3},{msg_opening_33,4},{msg_opening_34,5}
};

//----------------------------------
//メッセージ表示
//----------------------------------
//------------------------------------------------------------------
/**
 * @brief   メッセージ表示
 *
 * @param   wk				INTRO_DEMO_WORK
 * @param   msgID			メッセージID
 * @param   button_mode		A_BUTTON_WAIT=ボタン終了待ち : A_BUTTON_NOWAIT=ボタン待ちなし
 *
 * @retval  BOOL			TRUEでメッセージ表示終了
 */
//------------------------------------------------------------------
static BOOL Intro_MsgPrint( INTRO_DEMO_WORK * wk,u32 msgID, int button_mode )
{
	BOOL result = FALSE;

	switch(wk->msgseq){
	case MSGSET:
		//ビットマップ作成
		GF_BGL_BmpWinAddEx(wk->bgl,&wk->win_msg_print,&msg_windata );
		//初期クリア
		GF_BGL_BmpWinFill(&wk->win_msg_print,FBMP_COL_WHITE,0,0,
						INTRO_MSG_WIN_SX*DOTSIZE,INTRO_MSG_WIN_SY*DOTSIZE);
		//メッセージウインドウ初期表示
		BmpTalkWinWrite(&wk->win_msg_print,WINDOW_TRANS_ON,INTRO_TWINCHR_NUM,INTRO_TWINPLT_M_NUM);

		MsgPrintSkipFlagSet( MSG_SKIP_ON );		// メッセージスキップ有効
		MsgPrintAutoFlagSet( MSG_AUTO_OFF );	// メッセージオート送り無効

		//文字列の取得
		{
			STRBUF*	msg_tmp = STRBUF_Create( INTRO_STRBUF_SIZE, wk->heapID );
			//文字列バッファの作成
			wk->msgstr = STRBUF_Create(INTRO_STRBUF_SIZE, wk->heapID);

			MSGMAN_GetString( wk->msgman, msgID, msg_tmp );
			WORDSET_RegisterWord( wk->wordset, 0, wk->myname->strbuf, wk->mysex, TRUE, PM_LANG );
			WORDSET_RegisterWord( wk->wordset, 1, wk->rivalname->strbuf, PM_MALE, TRUE, PM_LANG );
			WORDSET_ExpandStr( wk->wordset, wk->msgstr, msg_tmp );
			STRBUF_Delete( msg_tmp );
		}
		//文字列の表示
		wk->msgID = GF_STR_PrintSimple(&wk->win_msg_print,FONT_TALK,wk->msgstr,0,0,MSGSPD,NULL);

		wk->msgseq = MSGDRAW;
		break;

	case MSGDRAW:
		//文字列描画待ち
		if(!(GF_MSG_PrintEndCheck(wk->msgID))){
			STRBUF_Delete(wk->msgstr);
			wk->msgseq = MSGWAIT;
		}
		break;

	case MSGWAIT:
		//終了待ち
		if( button_mode == A_BUTTON_WAIT ){
			if( KEYTRG( PAD_BUTTON_A ) ){
				wk->kt_st = APP_END_KEY;
				Snd_SePlay( SEQ_SE_DP_SELECT );
				result = TRUE;
			}
#if 0
			else if(sys.tp_trg){
				wk->kt_st = APP_END_TOUCH;
				Snd_SePlay( SEQ_SE_DP_SELECT );
				result = TRUE;
			}
#endif
		}else{
			result = TRUE;
		}

		// 終了処理
		if( result ){
			GF_BGL_BmpWinDel(&wk->win_msg_print);
			wk->msgseq = MSGSET;
		}
	}

	return result;
}

//------------------------------------------------------------------
/**
 * @brief   リスト表示用コールバック
 *
 * @param   wk		INTRO_DEMO_WORK
 * @param   param	コールバックパラメータ
 * @param   mode	コールバックモードパラメータ
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_BmpListMoveSeCall(BMPLIST_WORK * wk,u32 param,u8 mode)
{
	if( mode == 0 ){//初期化時は鳴らさない
		Snd_SePlay( SEQ_SE_DP_SELECT );
	}
}

//------------------------------------------------------------------
/**
 * @brief   リスト表示:BmpList設定参照
 *
 * @param   wk
 * @param   type
 * @param   button_mode
 *
 * @retval  BOOL
 */
//------------------------------------------------------------------
static BOOL Intro_BmpList( INTRO_DEMO_WORK * wk, INTRO_LISTTYPE type, int button_mode )
{
	BOOL result = FALSE;
	BMPLIST_HEADER				listheader_tmp;
	const BMPWIN_DAT*			windata;
	const INTRO_BMPLIST_TBL*	list;
	int	i,count;

	switch( wk->listseq ){
	case LISTSET:
		switch( type ){
		default:
		case LISTTYPE_YESNO:
			windata	= &yesno_windata;
			list	= yesno_list;
			count	= NELEMS(yesno_list);
			break;
		case LISTTYPE_MENU:
			windata	= &menu_windata;
			list	= menu_list;
			count	= NELEMS(menu_list);
			break;
		case LISTTYPE_NAME:
			windata	= &name_windata;
			if( CasetteVersion == VERSION_GOLD ){
				list  = name_list_d;
				count = NELEMS(name_list_d);
			} else {
				list  = name_list_p;
				count = NELEMS(name_list_p);
			}
			break;
		}
		//メニュービットマップ追加
		GF_BGL_BmpWinAddEx( wk->bgl, &wk->listwin, windata );
		//メニューリスト用文字列バッファ作成
		wk->listdata = BMP_MENULIST_Create( count, wk->heapID );
		//メニューリスト用文字列バッファ取得
		for( i=0; i<count; i++ ){
			BMP_MENULIST_AddArchiveString(wk->listdata,wk->msgman,list[i].msgID,list[i].retID);
		}
		//メニュービットマップリストヘッダ作成
		listheader_tmp = listheader_default;
		listheader_tmp.list	= wk->listdata;
		listheader_tmp.count = count;
		listheader_tmp.line = count;
		listheader_tmp.call_back = Intro_BmpListMoveSeCall;
		listheader_tmp.win  = &wk->listwin;
		//メニュービットマップリスト作成
		wk->list = BmpListSet(&listheader_tmp,0,0,wk->heapID);

		//ウインドウ（外枠）描画
		BmpMenuWinWrite(listheader_tmp.win,WINDOW_TRANS_OFF,INTRO_MWINCHR_NUM,INTRO_MWINPLT_M_NUM);
		//ＶＲＡＭ転送
		GF_BGL_BmpWinOn( &wk->listwin );

		wk->listseq = LISTSELECT;
		break;

	case LISTSELECT:
		wk->listres = BmpListMain(wk->list);
		if(wk->listres == BMPLIST_NULL){
				break;
		}
		if((wk->listres == BMPLIST_CANCEL)&&(button_mode == B_BUTTON_DISABLE)){
				break;
		}
		//選択リスト削除処理
		BmpMenuWinClear( &wk->listwin, WINDOW_TRANS_ON );
		GF_BGL_BmpWinDel( &wk->listwin );
		BmpListExit( wk->list, NULL, NULL );
		BMP_MENULIST_Delete( wk->listdata );
		Snd_SePlay( SEQ_SE_DP_SELECT );

		wk->listseq = LISTSET;
		result = TRUE;
		break;
	}
	return result;
}

//------------------------------------------------------------------
/**
 * @brief   ガイド表示
 *
 * @param   wk			INTRO_DEMO_WORK
 * @param   msgID		メッセージID
 * @param   type		GUIDETYPE_GUIDE=ぼうけんカイド: GUIDETYPE_OPERA=操作説明 : GUIDETYPE_EXPLAIN:説明選択
 * @param   pos_y		キャラ単位でY位置を指定
 * @param   siz_y		BMPWINを下にいくつキャラ確保するか
 *
 * @retval  BOOL		TRUEで表示終了
 */
//------------------------------------------------------------------
static BOOL _Intro_GuidePrintCore( INTRO_DEMO_WORK * wk,u32 msgID, INTRO_GUIDETYPE type, int pos_y, int siz_y )
{
	BOOL result = FALSE;
	BMPWIN_DAT	windata;

	switch(wk->guideseq){
	case GUIDESET:
		FRAME_OFF( INTRO_TEXT_M_FRAME )
		//文字列バッファの作成
		wk->msgstr = STRBUF_Create(INTRO_STRBUF_SIZE, wk->heapID);
		//文字列の取得
		MSGMAN_GetString(wk->msgman,msgID,wk->msgstr);

		// Y座標センタリング
		if( pos_y == GUIDE_PRINT_POS_Y_CENTER )
		{
			int line;
			line = STRBUF_GetLines( wk->msgstr );
			pos_y = (24 - line*2) / 2;
		}

		// サイズを文字列から取得
		if( siz_y == GUIDE_PRINT_SIZE_Y_AUTO )
		{
			siz_y = STRBUF_GetLines( wk->msgstr ) * 2;
			HOSAKA_PRINT("msgID:%d siz_y=%d \n", msgID, siz_y );
		}

		//ビットマップ作成＆初期クリア
		switch( type ){

		//ぼうけんガイド用
		case GUIDETYPE_GUIDE:
			windata = guide_windata;
			windata.pos_y = pos_y;
			windata.siz_y = siz_y;
			GF_BGL_BmpWinAddEx(wk->bgl,&wk->msgwin,&windata );
			GF_BGL_BmpWinFill(&wk->msgwin,0,0,0,
						INTRO_GUIDE_WIN_SX*DOTSIZE,INTRO_GUIDE_WIN_SY*DOTSIZE);
			//文字列の表示
			GF_STR_PrintColor(&wk->msgwin,FONT_SYSTEM,wk->msgstr,0,0,0,
							GF_PRINTCOLOR_MAKE(1, 2, 0),NULL);
			break;

		//操作説明用と説明選択用
		case GUIDETYPE_OPERA_L:
		case GUIDETYPE_OPERA:	case GUIDETYPE_EXPLAIN:
			windata = opera_windata;
			windata.pos_y = pos_y;
			windata.siz_y = siz_y;

			if( type == GUIDETYPE_OPERA_L ){ windata.pos_x += 4; }

			GF_BGL_BmpWinAddEx(wk->bgl,&wk->msgwin,&windata );
			GF_BGL_BmpWinFill(&wk->msgwin,0,0,0,
						INTRO_OPERA_WIN_SX*DOTSIZE,INTRO_OPERA_WIN_SY*DOTSIZE);
			//文字列の表示
			GF_STR_PrintColor(&wk->msgwin,FONT_SYSTEM,wk->msgstr,0,0,0,
							GF_PRINTCOLOR_MAKE(15, 2, 0),NULL);
			break;
		}
		STRBUF_Delete(wk->msgstr);
		wk->guideseq = GUIDEDISPON;
		break;

	case GUIDEDISPON:
		//ＶＲＡＭ転送
		GF_BGL_BmpWinOn( &wk->msgwin );
		wk->guideseq = GUIDEFADEIN;
		break;

	case GUIDEFADEIN:
		if( Intro_AlphaFade( wk, INTRO_TEXT_M_FRAME, ALPHA_FADEIN ) == TRUE ){
			wk->guideseq = GUIDEWAIT;

			// 操作説明の時は表示したままで一旦終了する
			if(type==GUIDETYPE_EXPLAIN){
				wk->guideseq = GUIDEFADEOUT;
				result = TRUE;
			}
		}
		break;

	case GUIDEWAIT:
		//終了待ち
		if( (KEYTRG( PAD_BUTTON_A ))||(KEYTRG( PAD_BUTTON_B )) )
		{
			if( sys.tp_trg ){
				wk->kt_st = APP_END_TOUCH;
			}else{
				wk->kt_st = APP_END_KEY;
			}

			Snd_SePlay( SEQ_SE_DP_SELECT );
			wk->guideseq = GUIDEFADEOUT;
		}
		break;

	case GUIDEFADEOUT:
		if( Intro_AlphaFade( wk, INTRO_TEXT_M_FRAME, ALPHA_FADEOUT ) == TRUE ){
			wk->guideseq = GUIDEEND;
		}
		break;

	case GUIDEEND:
		GF_BGL_BmpWinDel(&wk->msgwin);
		GF_BGL_ScrClear( wk->bgl, INTRO_TEXT_M_FRAME );
		wk->guideseq = GUIDESET;
		result = TRUE;
		break;
	}
	return result;
}

static BOOL Intro_GuidePrint( INTRO_DEMO_WORK * wk, u32 msgID, INTRO_GUIDETYPE type, int pos_y, int siz_y )
{
	return _Intro_GuidePrintCore( wk, msgID, type, pos_y, siz_y );
}

static BOOL Intro_GuidePrint2( INTRO_DEMO_WORK* wk, u32 msgID, INTRO_GUIDETYPE type )
{
	return _Intro_GuidePrintCore( wk, msgID, type, GUIDE_PRINT_POS_Y_CENTER, GUIDE_PRINT_SIZE_Y_AUTO );
}


//------------------------------------------------------------------
/**
 * @brief   ボタンメッセージを表示する
 *
 * @param   wk
 * @param   msgID1
 * @param   msgID2
 * @param   msgID3
 * @param   max
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_ButtonMsgPrint( INTRO_DEMO_WORK * wk, u32 msgID1, u32 msgID2, u32 msgID3, int max )
{
	int i,dotlen, center_x, offset_y;
	u32 msgid[3];
	STRBUF *strbuf;

	msgid[0] = msgID1;	msgid[1] = msgID2;	msgid[2] = msgID3;

	wk->button_num = max;

	// 選択肢が2個か3個かでBMPへの書き込みYオフセットを変える
	if(max==2){ offset_y = 4; }
	if(max==3){ offset_y = 8; }

	// BMPWIN確保、ボタン内メッセージ表示
	for(i=0;i<max;i++){

		//文字列バッファの作成
		strbuf = STRBUF_Create(INTRO_STRBUF_SIZE, wk->heapID);
		//文字列の取得
		MSGMAN_GetString(wk->msgman, msgid[i], strbuf);

		dotlen   = FontProc_GetPrintStrWidth( FONT_SYSTEM, strbuf, 0 );
		center_x = (buttonmsg_windata[max-2][i].siz_x*8-dotlen)/2;

		// BMPWIN準備＆表示
		GF_BGL_BmpWinAddEx(wk->bgl,&wk->button_msg[i],&buttonmsg_windata[max-2][i] );
		GF_BGL_BmpWinFill(&wk->button_msg[i],0,0,0,
				INTRO_OPERA_WIN_SX*DOTSIZE,INTRO_OPERA_WIN_SY*DOTSIZE);

		//文字列の表示
		GF_STR_PrintColor(&wk->button_msg[i], FONT_TOUCH, strbuf,
			center_x, offset_y, 0, GF_PRINTCOLOR_MAKE(15, 1, 0),NULL);


		//ＶＲＡＭ転送
		GF_BGL_BmpWinOn( &wk->button_msg[i] );

		STRBUF_Delete(strbuf);
	}

}

//------------------------------------------------------------------
/**
 * @brief   ボタンメッセージを消去
 *
 * @param   wk
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_ButtonMsgDel( INTRO_DEMO_WORK *wk )
{
	int i;

	// ボタンの中でBMPWIN削除
	for(i=0;i<wk->button_num;i++){
		GF_BGL_BmpWinDel(&wk->button_msg[i]);
	}
	GF_BGL_ScrClear( wk->bgl, INTRO_TEXT_M_FRAME );
}

//------------------------------------------------------------------
/**
 * @brief   グラフィック読み込み
			※背景はスクリーン、
			人物はキャラクターデータ＋パレット、
			ボタンはスクリーン＋キャラクターデータによって変化
 *
 * @param   wk		INTRO_DEMO_WORK
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_GraphicLoad( INTRO_DEMO_WORK* wk )
{

	//メイン画面背景キャラクター
	ArcUtil_BgCharSet(	ARC_INTRO, NARC_intro_back_m_NCGR,
						wk->bgl, INTRO_BACK_M_FRAME, 0, 0, 0, wk->heapID );
	//NULLキャラ設定
	GF_BGL_ClearCharSet( INTRO_TEXT_M_FRAME, 32, 0, wk->heapID );

	//サブ画面背景キャラクター
	ArcUtil_BgCharSet(	ARC_INTRO, NARC_intro_back_s_NCGR,
						wk->bgl, INTRO_BACK_S_FRAME, 0, 0, 0, wk->heapID );
	{//パレット（バージョンによって変化）
		int palIDm,palIDs;

		if( CasetteVersion == VERSION_GOLD ){
			palIDm = NARC_intro_back_m_d_NCLR;
			palIDs = NARC_intro_back_s_d_NCLR;
		} else {
			palIDm = NARC_intro_back_m_p_NCLR;
			palIDs = NARC_intro_back_s_p_NCLR;
		}
		ArcUtil_PalSet( ARC_INTRO, palIDm, PALTYPE_MAIN_BG, INTRO_BACKPLT_M_NUM * PALSIZE,
						PALSIZE * 3, wk->heapID );
		ArcUtil_PalSet( ARC_INTRO, palIDs, PALTYPE_SUB_BG, INTRO_BACKPLT_M_NUM * PALSIZE,
						PALSIZE * 5, wk->heapID );

		//性別選択の背景パレットを保持しておく
		{
			enum {
				SELECT_PAL_SIZE = 2,
				SELECT_PAL_OFFSET = 0xC, //透明色を抜いてスタート
			};

			void *adr;
			NNSG2dPaletteData *palData;
			u16 pal_col;

			adr = ArcUtil_PalDataGet( ARC_INTRO, palIDs, &palData, wk->heapID );

			pal_col = ((u16*)palData->pRawData)[ SELECT_PAL_OFFSET ];

			wk->select_pal = pal_col;

			sys_FreeMemoryEz( adr );

			HOSAKA_PRINT("get select pal:0x%x \n", wk->select_pal);
		}
	}

	// BGのスクリーンデータをメイン・サブ共に設定
	Intro_GraphicLoadSceneM( wk,   BGTYPE_MAIN_TUTORIAL0 );
	Intro_GraphicLoadScenePPL( wk, BGTYPE_MPPL_NULL, BGTYPE_MPPL_NULL );
	Intro_GraphicLoadSceneS( wk,   BGTYPE_SUB_NULL );

	GF_BGL_BackGroundColorSet( GF_BGL_FRAME0_M, INTRO_NULL_PALETTE );	//背景色初期化
	GF_BGL_BackGroundColorSet( GF_BGL_FRAME0_S, INTRO_NULL_PALETTE );	//背景色初期化

}


//------------------------------------------------------------------
/**
 * @brief   グラフィックシーン切り替え読み込み（メイン背景）
 *
 * @param   wk		INTRO_DEMO_WORK
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_GraphicLoadSceneM( INTRO_DEMO_WORK* wk, int type )
{
	int	dataIDTbl[] = { NARC_intro_back_m_null_NSCR,
						NARC_intro_back_m_t0_NSCR,
						NARC_intro_back_m_t1_NSCR,
						NARC_intro_back_m_t2_NSCR,
						NARC_intro_back_m_t3_NSCR,
						NARC_intro_back_m_g_NSCR };

//	int	dataIDTbl[] = { NARC_intro_back_m_null_NSCR,
//						NARC_intro_back_m_t1_NSCR,
//						NARC_intro_back_m_t2_NSCR,
//						NARC_intro_back_m_t3_NSCR,
//						NARC_intro_back_m_g_NSCR };

	if( type >= BGTYPE_MAIN_END ){
			return;
	}
	ArcUtil_ScrnSet(	ARC_INTRO, dataIDTbl[ type ],
						wk->bgl, INTRO_BACK_M_FRAME, 0, 0, 0, wk->heapID );
}


//------------------------------------------------------------------
/**
 * @brief   グラフィックシーン切り替え読み込み（メイン人物）
 *
 * @param   wk		INTRO_DEMO_WORK
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_GraphicLoadScenePPL( INTRO_DEMO_WORK* wk, int type1, int type2 )
{
	int	dataIDTbl[][2] = {	{ 0, 0 },	//読み込みなし
							{ NARC_intro_doctor_NCGR,		NARC_intro_doctor_NCLR },
							{ NARC_intro_hero_0_NCGR,		NARC_intro_hero_NCLR },
							{ NARC_intro_hero_1_NCGR,		NARC_intro_hero_NCLR },
							{ NARC_intro_hero_2_NCGR,		NARC_intro_hero_NCLR },
							{ NARC_intro_hero_3_NCGR,		NARC_intro_hero_NCLR },
							{ NARC_intro_heroine_0_NCGR,	NARC_intro_heroine_NCLR },
							{ NARC_intro_heroine_1_NCGR,	NARC_intro_heroine_NCLR },
							{ NARC_intro_heroine_2_NCGR,	NARC_intro_heroine_NCLR },
							{ NARC_intro_heroine_3_NCGR,	NARC_intro_heroine_NCLR },
						};

	if(( type1 != BGTYPE_MPPL_NULL )&&( type2 < BGTYPE_MPPL_END )){
		ArcUtil_BgCharSet(	ARC_INTRO, dataIDTbl[ type1 ][0],
							wk->bgl, INTRO_PPL1_M_FRAME, 0, 0, 0, wk->heapID );
		ArcUtil_PalSet( ARC_INTRO, dataIDTbl[ type1 ][1],
							PALTYPE_MAIN_BG, INTRO_PPL1PLT_M_NUM * PALSIZE, PALSIZE, wk->heapID );
		ArcUtil_ScrnSet(	ARC_INTRO, NARC_intro_back_m_ppl_NSCR,
							wk->bgl, INTRO_PPL1_M_FRAME, 0, 0, 0, wk->heapID );
		Intro_BGscrPalChange( wk, INTRO_PPL1_M_FRAME, INTRO_PPL1PLT_M_NUM );
	}
	if(( type2 != BGTYPE_MPPL_NULL )&&( type2 < BGTYPE_MPPL_END )){
		ArcUtil_BgCharSet(	ARC_INTRO, dataIDTbl[ type2 ][0],
							wk->bgl, INTRO_PPL2_M_FRAME, 0, 0, 0, wk->heapID );
		ArcUtil_PalSet( ARC_INTRO, dataIDTbl[ type2 ][1],
						PALTYPE_MAIN_BG, INTRO_PPL2PLT_M_NUM * PALSIZE, PALSIZE, wk->heapID );
		ArcUtil_ScrnSet(	ARC_INTRO, NARC_intro_back_m_ppl_NSCR,
							wk->bgl, INTRO_PPL2_M_FRAME, 0, 0, 0, wk->heapID );
		Intro_BGscrPalChange( wk, INTRO_PPL2_M_FRAME, INTRO_PPL2PLT_M_NUM );
	}
}


//------------------------------------------------------------------
/**
 * @brief   グラフィックシーン切り替え読み込み（サブ背景）
 *
 * @param   wk		INTRO_DEMO_WORK
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_GraphicLoadSceneS( INTRO_DEMO_WORK* wk, int type )
{
	int	dataIDTbl[] = { NARC_intro_back_s_null_NSCR,
						NARC_intro_back_s_guide_NSCR,
						NARC_intro_back_s_guide_NSCR,
						NARC_intro_back_s_yn_NSCR,
						NARC_intro_button_sex_NSCR };

	if( type >= BGTYPE_SUB_END ){
			return;
	}
	ArcUtil_ScrnSet(	ARC_INTRO, dataIDTbl[ type ],
						wk->bgl, INTRO_BACK_S_FRAME, 0, 0, 0, wk->heapID );

	if( type == BGTYPE_SUB_TUTORIALBALL ){
		Intro_BGscrPalChange( wk, INTRO_BACK_S_FRAME, INTRO_TUTPLT_S_NUM );
	} else if( type == BGTYPE_SUB_GUIDEBALL ){
		Intro_BGscrPalChange( wk, INTRO_BACK_S_FRAME, INTRO_GUIDEPLT_S_NUM );
	}
}

//----------------------------------
//グラフィック読み込み（ポケモン）
//----------------------------------
#define MONSDATASIZE	( 10*10 )
static const u8 monscr_tbl[] = {
	 0, 1, 2, 3, 4, 5, 6, 7,64,65,
	 8, 9,10,11,12,13,14,15,66,67,
	16,17,18,19,20,21,22,23,68,69,
	24,25,26,27,28,29,30,31,70,71,
	32,33,34,35,36,37,38,39,72,73,
	40,41,42,43,44,45,46,47,74,75,
	48,49,50,51,52,53,54,55,76,77,
	56,57,58,59,60,61,62,63,78,79,
	80,81,82,83,88,89,90,91,96,97,
	84,85,86,87,92,93,94,95,98,99,
};

static const u16 monpal_null_tbl[] = {
	0x6a3c,0x6a3c,0x6a3c,0x6a3c,0x6a3c,0x6a3c,0x6a3c,0x6a3c,
	0x6a3c,0x6a3c,0x6a3c,0x6a3c,0x6a3c,0x6a3c,0x6a3c,0x6a3c,
//	0x54d9,0x54d9,0x54d9,0x54d9,0x54d9,0x54d9,0x54d9,0x54d9,
//	0x54d9,0x54d9,0x54d9,0x54d9,0x54d9,0x54d9,0x54d9,0x54d9,
};


//------------------------------------------------------------------
/**
 * @brief   ポケモン正面画像を読み込んでBGで表示する
 *
 * @param   wk
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_GraphicLoadScenePOKE( INTRO_DEMO_WORK* wk )
{
	SOFT_SPRITE_ARC ssa;
	void*	monsscr;
	void*	monscgx;
	void*	monspal;
	void*	monspal_null;

	int frame_m    = INTRO_PPL2_M_FRAME;
	int pal_m      = INTRO_PPL2PLT_M_NUM;
	int pal_m_null = INTRO_PPLNULLPLT_M_NUM;

	//アーカイブファイル情報取得
	PokeGraArcDataGet( &ssa, INTRO_MONSNO, PARA_MALE, PARA_FRONT, PARA_NORMAL, 0, 0 );

	monsscr = sys_AllocMemory( wk->heapID, MONSDATASIZE*2 );
	{
		int	i;
		for( i=0; i<MONSDATASIZE; i++ ) ((u16*)monsscr)[i] = monscr_tbl[i]+1;
	}
	monscgx      = ChangesInto_BattlePokeData_Alloc( ssa.arc_no, ssa.index_chr, wk->heapID );
	monspal      = ChangesInto_BattlePokePalData_Alloc( ssa.arc_no, ssa.index_pal, wk->heapID );
	monspal_null = (void*)monpal_null_tbl;

	// 金銀ではメイン画面だけで良いので下画面転送をやめた
	GF_BGL_ScrFill( wk->bgl, frame_m, 0, 0, 0, 32, 24, pal_m_null);
	GF_BGL_ScrWrite( wk->bgl, frame_m, monsscr, 11, 10, 10, 10 );
	Intro_BGscrPalChange( wk, frame_m, pal_m_null );
	GF_BGL_ClearCharSet( frame_m, 32, 0, wk->heapID );
	GF_BGL_LoadCharacter( wk->bgl, frame_m, monscgx, MONSDATASIZE*0x20, 1 );
	GF_BGL_PaletteSet( frame_m, monspal, PALSIZE, PALSIZE*pal_m );
	GF_BGL_PaletteSet( frame_m, monspal_null, PALSIZE, PALSIZE*pal_m_null );


	sys_FreeMemoryEz( monspal );
	sys_FreeMemoryEz( monscgx );
	sys_FreeMemoryEz( monsscr );
}


#define BTNTYPE2_BG_OFFSET_MALE		( 0x88 )
#define BTNTYPE2_BG_OFFSET_FEMALE	( 0 )

//------------------------------------------------------------------
/**
 * @brief   グラフィック読み込み（サブボタン）
 *
 * @param   wk		INTRO_DEMO_WORK
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_GraphicLoadSceneBTN( INTRO_DEMO_WORK* wk, int type )
{
	const int	dataIDTbl[][2] = {
		{	NARC_intro_button_s_3_NSCR,	NARC_intro_button_mapping_NCGR	},
		{	NARC_intro_button_s_name_NSCR,	NARC_intro_button_mapping_NCGR	},
		{	NARC_intro_button_s_yn_NSCR,	NARC_intro_button_mapping_NCGR	},
	 };




	//サブボタンスクリーン
	ArcUtil_ScrnSet(	ARC_INTRO, dataIDTbl[type][0],
						wk->bgl, INTRO_PBTN_S_FRAME, 0, 0, 0, wk->heapID );
	Intro_BGscrPalChange( wk, INTRO_PBTN_S_FRAME, INTRO_BTNBALLPLT_S_NUM );
	ArcUtil_PalSet(		ARC_INTRO, NARC_intro_button_s_NCLR, PALTYPE_SUB_BG,
						INTRO_BTNBALLPLT_S_NUM * PALSIZE, PALSIZE * 3, wk->heapID );

	//NULLキャラ設定
	GF_BGL_ClearCharSet( INTRO_PBTN_S_FRAME, 32, 0, wk->heapID );
	//ボタン個体読み込み
	ArcUtil_BgCharSet(	ARC_INTRO, dataIDTbl[type][1],
						wk->bgl, INTRO_PBTN_S_FRAME, 0, 0, 0, wk->heapID );

	GF_BGL_ScrollReq( wk->bgl, INTRO_PPL1_S_FRAME, GF_BGL_SCROLL_Y_SET, 0);

	// 「名前・やめる」選択の時は性別によって位置を移動させる
	if( type==BGTYPE_SUBBTN_2_TATE ){
		if(wk->mysex==PM_MALE){
			GF_BGL_ScrollReq( wk->bgl, INTRO_TEXT_S_FRAME, GF_BGL_SCROLL_X_SET, BTNTYPE2_BG_OFFSET_MALE);
			GF_BGL_ScrollReq( wk->bgl, INTRO_PBTN_S_FRAME, GF_BGL_SCROLL_X_SET, BTNTYPE2_BG_OFFSET_MALE);
			GF_BGL_ScrollReq( wk->bgl, INTRO_PPL1_S_FRAME, GF_BGL_SCROLL_X_SET, BTNTYPE2_BG_OFFSET_MALE);
		}else{
			GF_BGL_ScrollReq( wk->bgl, INTRO_TEXT_S_FRAME, GF_BGL_SCROLL_X_SET, BTNTYPE2_BG_OFFSET_FEMALE);
			GF_BGL_ScrollReq( wk->bgl, INTRO_PBTN_S_FRAME, GF_BGL_SCROLL_X_SET, BTNTYPE2_BG_OFFSET_FEMALE);
			GF_BGL_ScrollReq( wk->bgl, INTRO_PPL1_S_FRAME, GF_BGL_SCROLL_X_SET, BTNTYPE2_BG_OFFSET_FEMALE);
		}
	}

}

static const int CursorDataIDTbl[][4]={
		{ NARC_intro_button_cursor_NSCR,     3, },
		{ NARC_intro_button_cursor2_NSCR,    2, },
		{ NARC_intro_button_cursor2_NSCR,    2, },
		{ NARC_intro_button_cursor_sex_NSCR, 2, },
};

//------------------------------------------------------------------
/**
 * @brief
 *
 * @param   cursor
 * @param   type
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_ButtonInit( INTRO_CURSOR_WORK *cursor, int type )
{
	cursor->pos      = 0;
	cursor->start    = 0;
	cursor->max      = CursorDataIDTbl[type][1];
	cursor->endwait  = 0;
	cursor->wait     = 0;
	cursor->wait_max = 16;
	cursor->on       = 0;
}

//------------------------------------------------------------------
/**
 * @brief   下画面ボタンのカーソル初期化
 *
 * @param   wk		INTRO_DEMO_WORK
 * @param   type	BTNTYPE_3 or BTNTYPE_2
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_ButtonCursorAppear( INTRO_DEMO_WORK *wk, int type )
{
	// カーソルワーク初期化
	wk->cursor.start   = 0;
	wk->cursor.max     = CursorDataIDTbl[type][1];
	wk->cursor.wait    = 0;
//	wk->cursor.on      = 0;
	wk->cursor.wait_max = 16;


	//サブボタンスクリーン
	ArcUtil_ScrnSet(	ARC_INTRO, CursorDataIDTbl[type][0],
						wk->bgl, INTRO_PPL1_S_FRAME, 0, 0, 0, wk->heapID );
//	Intro_BGscrPalChange( wk, INTRO_PPL1_S_FRAME, INTRO_SUBDISP_CURSOR );
//	ArcUtil_PalSet(		ARC_INTRO, NARC_intro_button_s_NCLR, PALTYPE_SUB_BG,
//						INTRO_SUBDISP_CURSOR * PALSIZE, PALSIZE, wk->heapID );

	//ボタン個体読み込み
	ArcUtil_BgCharSet(	ARC_INTRO, NARC_intro_button_cusor_NCGR,
						wk->bgl, INTRO_PPL1_S_FRAME, 0, 0, 0, wk->heapID );

}


static const cursor_bg_pos[][3]={
	{ 0, 0x1c7, 0x18f},
	{ 0, 0x1af, 0    },
	{ 0, 0x1af, 0    },
};

//------------------------------------------------------------------
/**
 * @brief   ３択・２択選択肢（タッチ・キー両対応版）
 *
 * @param   wk		INTRO_DEMO_WORK
 * @param   type	BTNTYPE_3 or BTNTYPE_2
 *
 * @retval  int		選択中は-1,決定した時は0-2
 */
//------------------------------------------------------------------
static int Intro_ButtonMain( INTRO_DEMO_WORK *wk, int type )
{
	int result = -1;

	const RECT_HIT_TBL button_tbl[][4]={
		{{ 20,  50, 50, 213,},	{ 76, 106, 50, 213,}, 	{132, 162, 50, 213,},  {TP_HIT_END,0,0,0},	},	// 3択
		{{ 26,  83, 128+10, 128+125,}, 	{108, 164, 128+10, 128+125,},{TP_HIT_END,0,0,0},			},	// 2択男
		{{ 26,  83, 10, 125,}, 	{108, 164, 10, 125,},{TP_HIT_END,0,0,0},							},	// 2択女
	};

	// 決定後のアニメ待ち
	if(wk->cursor.endwait!=0){
		wk->cursor.endwait++;
		if(wk->cursor.endwait > 20){
			wk->cursor.endwait = 0;
			result = wk->cursor.pos;
		}
	}else{
		// タッチパネル処理
		if(sys.tp_trg){
			int touch = GF_TP_RectHitTrg( button_tbl[type] );
			if(touch!=TP_HIT_NONE){
				Intro_ButtonCursorAppear( wk, type );
				FRAME_ON( INTRO_PPL1_S_FRAME )	// 下画面カーソル
				wk->cursor.pos     = touch;
				GF_BGL_ScrollReq( wk->bgl, INTRO_PPL1_S_FRAME, GF_BGL_SCROLL_Y_SET,
												cursor_bg_pos[type][wk->cursor.pos]);
				wk->cursor.endwait = 1;
				wk->cursor.wait_max = 2;
				Snd_SePlay( SEQ_SE_DP_SELECT );
			}
		}else{
		// キー処理
			if(wk->cursor.on==0){
				// カーソル表示していなかった
				if(sys.trg&(PAD_BUTTON_A|PAD_KEY_UP|PAD_KEY_DOWN|PAD_BUTTON_B)){
					Snd_SePlay( SEQ_SE_DP_SELECT );
					Intro_ButtonCursorAppear( wk, type );
					FRAME_ON( INTRO_PPL1_S_FRAME )	// 下画面カーソル
					wk->cursor.on = 1;
				}
			}else{
				// カーソル表示後
				if(sys.trg&PAD_KEY_UP){
					if(wk->cursor.pos!=0){
						wk->cursor.pos--;
						GF_BGL_ScrollReq( wk->bgl, INTRO_PPL1_S_FRAME, GF_BGL_SCROLL_Y_SET,
														cursor_bg_pos[type][wk->cursor.pos]);
						Snd_SePlay( SEQ_SE_DP_SELECT );
					}
				}else if(sys.trg&PAD_KEY_DOWN){
					if(wk->cursor.pos!=(wk->cursor.max-1)){
						wk->cursor.pos++;
						GF_BGL_ScrollReq( wk->bgl, INTRO_PPL1_S_FRAME, GF_BGL_SCROLL_Y_SET,
														cursor_bg_pos[type][wk->cursor.pos]);
						Snd_SePlay( SEQ_SE_DP_SELECT );
					}

				}else if(sys.trg&PAD_BUTTON_A){
					wk->cursor.endwait = 1;
					wk->cursor.wait_max = 2;
//					result = wk->cursor.pos;
					Snd_SePlay( SEQ_SE_DP_SELECT );
				}else if(sys.trg&PAD_BUTTON_B){
//					wk->cursor.pos=1;
					wk->cursor.pos=wk->cursor.max-1;
					wk->cursor.endwait = 1;
					wk->cursor.wait_max = 2;
					GF_BGL_ScrollReq( wk->bgl, INTRO_PPL1_S_FRAME, GF_BGL_SCROLL_Y_SET,
														cursor_bg_pos[type][wk->cursor.pos]);
					Snd_SePlay( SEQ_SE_DP_SELECT );
				}
			}
		}
	}

	if(wk->cursor.endwait!=0){
		wk->cursor.wait++;
		if(wk->cursor.wait>wk->cursor.wait_max){
			wk->cursor.blink^=1;
			wk->cursor.wait=0;
			if(wk->cursor.blink){
				FRAME_ON( INTRO_PPL1_S_FRAME )	// 下画面カーソル
			}else{
				FRAME_OFF( INTRO_PPL1_S_FRAME )	// 下画面カーソル
			}
		}
	}

	return result;
}

#define COLOR_FEMALE_BODY	( 12 )
#define COLOR_FEMALE_FLAME	( 13 )
#define COLOR_MALE_BODY		( 14 )
#define COLOR_MALE_FLAME	( 15 )

#define COLOR_SELECT_FLAME		( ( 7<<10) | ( 7<<5) | 31 )	// 赤フレーム
#define COLOR_NOSELECT_FLAME	( (28<<10) | (28<<5) | 27 )

static const col_target[2] = {
	COLOR_FEMALE_BODY, COLOR_MALE_BODY,
};

//-----------------------------------------------------------------------------
/**
 *	@brief	パレットの各要素に色を加算・減算する
 *
 *	@param	const u16 base_col
 *	@param	u8 add_col
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static u16 add_rgb( const u16 base_col, const s8 add_col )
{
	int r,g,b;
	u16 ret_col;

	r = base_col & 0x1f; // 5 bit
	g = (base_col >> 5) & 0x1f; // 5 bit
	b = base_col >> 10;

	r += add_col;
	g += add_col;
	b += add_col;

	r = MATH_CLAMP(r, 0, 31);
	g = MATH_CLAMP(g, 0, 31);
	b = MATH_CLAMP(b, 0, 31);

//	HOSAKA_PRINT("r:%d g:%d b:%d \n",r,g,b);

	ret_col = (b<<10) | (g<<5) | r;

	return ret_col;
}

//------------------------------------------------------------------
/**
 * @brief   性別選択画面の枠と背景のカラーを変更する
 *
 * @param   wk
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void MaleFemale_ColChange(INTRO_DEMO_WORK *wk, BOOL b_init )
{
	const int trans_size = 2*2;
	int add_col = 0;
	u16 col[2];

	GF_ASSERT( wk->cursor.pos == 0 || wk->cursor.pos == 1 );

	if( b_init == FALSE ) {
		// 選択側
		add_col = Sin360R( wk->cursor.pal_fade_seq++ * 10 ) * 8;
		add_col >>= FX32_SHIFT;

//		HOSAKA_PRINT("add_col:%d \n", add_col);
	}
	else {
		// 初期化処理
		wk->cursor.pal_fade_seq = 0;
	}

	col[0] = add_rgb( wk->select_pal, add_col );
	col[1] = add_rgb( COLOR_SELECT_FLAME, 0 );

	GF_BGL_PaletteSet( INTRO_PBTN_S_FRAME, (void*)col, trans_size, 2*col_target[wk->cursor.pos] );

	// 非選択側
	col[0] = wk->select_pal;
	col[1] = COLOR_NOSELECT_FLAME;

	GF_BGL_PaletteSet( INTRO_PBTN_S_FRAME, (void*)col, trans_size, 2*col_target[!wk->cursor.pos] );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	双方を非選択状態にする
 *
 *	@param	INTRO_DEMO_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void MaleFmale_NoSelect( INTRO_DEMO_WORK* wk )
{
	const int trans_size = 2*2;
	u16 col[2];

	// 非選択側
	col[0] = wk->select_pal;
	col[1] = COLOR_NOSELECT_FLAME;

	GF_BGL_PaletteSet( INTRO_PBTN_S_FRAME, (void*)col, trans_size, 2*col_target[0] );
	GF_BGL_PaletteSet( INTRO_PBTN_S_FRAME, (void*)col, trans_size, 2*col_target[1] );

}

//------------------------------------------------------------------
/**
 * @brief   性別選択の時の判定処理
 *
 * @param   wk
 *
 * @retval  int
 */
//------------------------------------------------------------------
static int Intro_SelectSex( INTRO_DEMO_WORK *wk )
{
	int result = FALSE;
	const RECT_HIT_TBL sex_tbl[]={
		{25,173,18,111,},	{ 25,173, 144, 239,}, 	{TP_HIT_END,0,0,0},
	};

	// タッチパネル処理
	if(sys.tp_trg){
		int touch = GF_TP_RectHitTrg( sex_tbl );
		if(touch!=TP_HIT_NONE){
			wk->cursor.pos     = touch;
			wk->cursor.endwait = 1;
			wk->cursor.wait_max = 2;
			MaleFemale_ColChange( wk, TRUE );
			Snd_SePlay( SEQ_SE_DP_SELECT );
			wk->gender_work    = touch;
			result = TRUE;
		}
	}else{
	// キー処理
		if(wk->cursor.on==0){
			// カーソル表示していなかった
			if(sys.trg&(PAD_BUTTON_A|PAD_KEY_LEFT|PAD_KEY_RIGHT)){
				Snd_SePlay( SEQ_SE_DP_SELECT );
				wk->cursor.on = 1;
				MaleFemale_ColChange( wk, TRUE );
			}
		}else{
			// カーソル表示後

			// 背景パレットアニメ
			MaleFemale_ColChange( wk, FALSE );

			if(sys.trg&PAD_KEY_LEFT){
				if(wk->cursor.pos!=0){
					wk->cursor.pos--;
					Snd_SePlay( SEQ_SE_DP_SELECT );
				}
			}else if(sys.trg&PAD_KEY_RIGHT){
				if(wk->cursor.pos!=(wk->cursor.max-1)){
					wk->cursor.pos++;
					Snd_SePlay( SEQ_SE_DP_SELECT );
				}

			}else if(sys.trg&PAD_BUTTON_A){
				wk->cursor.on = 0;
				wk->cursor.endwait = 1;
				wk->cursor.wait_max = 2;
				MaleFemale_ColChange( wk, TRUE );
				Snd_SePlay( SEQ_SE_DP_SELECT );
				wk->gender_work    = wk->cursor.pos;
				result = TRUE;
			}
		}
	}
	return result;
}

//------------------------------------------------------------------
/**
 * @brief   スクロール（メイン人物）
 *
 * @param   wk		INTRO_DEMO_WORK
 * @param   frame	BG面
 * @param   type	SCROLL_CENTER, SCROLL_LEFT, SCROLL_RIGHT
 *
 * @retval  BOOL	移動が終了したらTRUE
 */
//------------------------------------------------------------------
static BOOL Intro_PPLScroll( INTRO_DEMO_WORK * wk,int frame, int type )
{
	BOOL result = FALSE;
	GXBlendPlaneMask plane1;

	if( type == SCROLL_CENTER ){
		{
			int scrx = GF_BGL_ScrollGetX( wk->bgl, frame );

			if( scrx != 0 ){
				if( scrx > 0 ){
					GF_BGL_ScrollSet( wk->bgl, frame, GF_BGL_SCROLL_X_DEC, 4 );
				} else {
					GF_BGL_ScrollSet( wk->bgl, frame, GF_BGL_SCROLL_X_INC, 4 );
				}
			} else {
				result = TRUE;
			}
		}
	}else if ( type == SCROLL_RIGHT ){
		if( GF_BGL_ScrollGetX( wk->bgl, frame ) != -8*6 ){
			GF_BGL_ScrollSet( wk->bgl, frame, GF_BGL_SCROLL_X_DEC, 4 );
		} else {
			result = TRUE;
		}
	}else if ( type == SCROLL_LEFT ){
		if( GF_BGL_ScrollGetX( wk->bgl, frame ) != 0 ){
			GF_BGL_ScrollSet( wk->bgl, frame, GF_BGL_SCROLL_X_INC, 4 );
		} else {
			result = TRUE;
		}
	}
	return result;
}


//------------------------------------------------------------------
/**
 * @brief   アニメーション（主人公）初期化
 *
 * @param   wk		INTRO_DEMO_WORK
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_MineAnimeInit( INTRO_DEMO_WORK * wk )
{
	wk->bganime_count_male			= 0;
	wk->bganime_count_wait_male		= 0;
	wk->bganime_count_female		= 0;
	wk->bganime_count_wait_female	= 0;
}

//------------------------------------------------------------------
/**
 * @brief   アニメーション（主人公）メイン
 *
 * @param   wk
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_MineAnime( INTRO_DEMO_WORK * wk )
{
	if( wk->mysex == PM_MALE ){
		if( wk->bganime_count_wait_male ){
			wk->bganime_count_wait_male--;
		} else {
			wk->bganime_count_male++;
			wk->bganime_count_male &= 3;	//４種類
			wk->bganime_count_wait_male = 4;
		}
		G2_SetBlendAlpha( GX_BLEND_PLANEMASK_BG2, GX_BLEND_PLANEMASK_BG3, 6, 10 );
		{
			int	dataIDTbl_Male[] = {	NARC_intro_hero_0_NCGR, NARC_intro_hero_1_NCGR,
										NARC_intro_hero_2_NCGR,	NARC_intro_hero_3_NCGR };
			ArcUtil_BgCharSet(	ARC_INTRO, dataIDTbl_Male[ wk->bganime_count_male ],
								wk->bgl, INTRO_PPL1_M_FRAME, 0, 0, 0, wk->heapID );
		}
	} else {
		if( wk->bganime_count_wait_female ){
			wk->bganime_count_wait_female--;
		} else {
			wk->bganime_count_female++;
			wk->bganime_count_female &= 3;	//４種類
			wk->bganime_count_wait_female = 4;
		}
		G2_SetBlendAlpha( GX_BLEND_PLANEMASK_BG1, GX_BLEND_PLANEMASK_BG3, 6, 10 );
		{
			int	dataIDTbl_Female[] = {	NARC_intro_heroine_0_NCGR, NARC_intro_heroine_1_NCGR,
										NARC_intro_heroine_2_NCGR,	NARC_intro_heroine_3_NCGR };

			ArcUtil_BgCharSet(	ARC_INTRO, dataIDTbl_Female[ wk->bganime_count_female ],
								wk->bgl, INTRO_PPL2_M_FRAME, 0, 0, 0, wk->heapID );
		}
	}
}

static void Intro_MineAnimeEnd( INTRO_DEMO_WORK * wk )
{
	G2_BlendNone();
}


//------------------------------------------------------------------
/**
 * @brief   縮小アニメーション（主人公）初期化
 *
 * @param   wk
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void Intro_MineAnimeMinInit( INTRO_DEMO_WORK * wk )
{
	wk->work[0]	= 0;
	wk->work[1]	= 0;
}

//------------------------------------------------------------------
/**
 * @brief   縮小アニメーション（主人公）メイン
 *
 * @param   wk
 *
 * @retval  BOOL
 */
//------------------------------------------------------------------
static BOOL Intro_MineMinAnime( INTRO_DEMO_WORK * wk )
{
	BOOL result = FALSE;
	int dataID;

	if( wk->work[1] ){
		wk->work[1]--;
	} else {
		wk->work[0]++;
		wk->work[1] = 8;
	}
	if( wk->mysex == PM_MALE ){
		{
			int	dataIDTbl_Male[] = {	NARC_intro_hero_0_NCGR,		NARC_intro_hero_m1_NCGR,
										NARC_intro_hero_m2_NCGR,	NARC_intro_hero_m3_NCGR,
										NARC_intro_hero_m4_NCGR,	0xff };
			dataID = dataIDTbl_Male[ wk->work[0] ];
		}
	} else {
		{
			int	dataIDTbl_Female[] = {	NARC_intro_heroine_0_NCGR,	NARC_intro_heroine_m1_NCGR,
										NARC_intro_heroine_m2_NCGR,	NARC_intro_heroine_m3_NCGR,
										NARC_intro_heroine_m4_NCGR,	0xff };

			dataID = dataIDTbl_Female[ wk->work[0] ];
		}
	}
	if( dataID == 0xff ){
		result = TRUE;
	} else {
		ArcUtil_BgCharSet(	ARC_INTRO, dataID, wk->bgl, INTRO_PPL1_M_FRAME, 0, 0, 0, wk->heapID );
	}
	return result;
}




//------------------------------------------------------------------
/**
 * @brief   時間によって変わる博士のメッセージを決める
 *
 * @param   none
 *
 * @retval  u32		msg_opening_01_01〜msg_opening_01_05
 */
//------------------------------------------------------------------
static u32 Intro_OhkidoMsgSet(void)
{
	RTCDate date;
	RTCTime time;
	u32     hm=0;
	u32     msgid = msg_opening_01_01;

	GF_RTC_GetDateTime(&date, &time);

	hm = time.hour*100+time.minute;		// 「時刻*100+分」に変換

/*
    GF1067  【イントロ画面】オーキドの挨拶が朝の言葉になる
    3:59,18:59,23:59の挨拶が時間に合わせた正しい言葉ではなく朝の挨拶になってしまう
    海外版バグSYSTEM1607
*/
#if GS_AFTERMASTER_GF1067_20091015_FIX
	if( hm>=400 && hm<=1059){
		msgid = msg_opening_01_01;
	}else if( hm>=1100 && hm<=1559){
		msgid = msg_opening_01_02;
	}else if( hm>=1600 && hm<=1859){
		msgid = msg_opening_01_03;
	}else if( hm>=1900 && hm<=2359){
		msgid = msg_opening_01_04;
	}else if( hm>=0    && hm<=359){
		msgid = msg_opening_01_05;
	}
#else
	if( hm>=400 && hm<1059){
		msgid = msg_opening_01_01;
	}else if( hm>=1100 && hm<1559){
		msgid = msg_opening_01_02;
	}else if( hm>=1600 && hm<1859){
		msgid = msg_opening_01_03;
	}else if( hm>=1900 && hm<2359){
		msgid = msg_opening_01_04;
	}else if( hm>=0    && hm<359){
		msgid = msg_opening_01_05;
	}
#endif

	return msgid;
}


static const s16 move_tbl[][3]={
	{   0, -52, -2},
	{ -52,   0,  2},
};

enum{
	BG_MOVE_INIT=0,
	BG_MOVE_MAIN,
	BG_MOVE_END,
};

//------------------------------------------------------------------
/**
 * @brief   BG横スクロール処理
 *
 * @param   wk
 * @param   frame		BG面設定
 * @param   movetype	移動タイプ(MOVE_TYPE_CENTER_RIGHT等）
 *
 * @retval  BOOL		TRUEで移動終了
 */
//------------------------------------------------------------------
static BOOL Intro_BgMove( INTRO_DEMO_WORK *wk, int frame, int movetype )
{
	switch( wk->bgmove_seq ){
	case BG_MOVE_INIT:
		wk->bgmove_seq = BG_MOVE_MAIN;
		wk->bgmove_x   = move_tbl[movetype][0];
		break;
	case BG_MOVE_MAIN:
		wk->bgmove_x += move_tbl[movetype][2];
		if(move_tbl[movetype][2]>0){
			if(wk->bgmove_x >= move_tbl[movetype][1]){
				wk->bgmove_x   = move_tbl[movetype][1];
				wk->bgmove_seq = BG_MOVE_END;
			}
		}else{
			if(wk->bgmove_x <= move_tbl[movetype][1]){
				wk->bgmove_x   = move_tbl[movetype][1];
				wk->bgmove_seq = BG_MOVE_END;
			}
		}
		GF_BGL_ScrollSet( wk->bgl, frame, GF_BGL_SCROLL_X_SET, wk->bgmove_x );
		break;
	case BG_MOVE_END:
		wk->bgmove_seq = BG_MOVE_INIT;
		return TRUE;
		break;
	}
	return FALSE;
}


//----------------------------------
//ポケモン登場演出
//----------------------------------
#define POKE_FSTPOSY	(-8*13)
#define POKE_TOPPOSY	(8*14)
#define GRABITY_VAL		(9)
#define FIRSTSPEED		(8)

//------------------------------------------------------------------
/**
 * @brief   ポケモン登場演出
 *
 * @param   wk		INTRO_DEMO_WORK
 * @param   seq		制御シーケンス（関数内で遷移）
 *
 * @retval  BOOL	TRUEで終了
 */
//------------------------------------------------------------------
static BOOL Intro_PokeScroll( INTRO_DEMO_WORK * wk, int* seq )
{
	BOOL result = FALSE;

	switch( *seq ){
	case 0:
		GF_BGL_ScrollSet( wk->bgl, INTRO_PPL2_M_FRAME, GF_BGL_SCROLL_X_SET, 0 );
		GF_BGL_ScrollSet( wk->bgl, INTRO_PPL2_M_FRAME, GF_BGL_SCROLL_Y_SET, POKE_FSTPOSY );
		GF_BGL_PrioritySet( INTRO_PPL2_M_FRAME, 0 );
		FRAME_ON( INTRO_PPL1_S_FRAME )

		wk->work[5] = 0;
		wk->work[6] = FIRSTSPEED;
		wk->work[7] = 0;
		*seq = 1;
		break;

	case 1:
		{
			int scrx = GF_BGL_ScrollGetX( wk->bgl, INTRO_PPL2_M_FRAME );
			int scry = GF_BGL_ScrollGetY( wk->bgl, INTRO_PPL1_S_FRAME );

			int plus = wk->work[6] * GRABITY_VAL * wk->work[7];
			int minus = GRABITY_VAL * wk->work[7] * wk->work[7] / 2;
			int y = plus - minus;

			if( scry < 8*11 ){
				wk->work[7]++;
				GF_BGL_ScrollSet( wk->bgl, INTRO_PPL2_M_FRAME, GF_BGL_SCROLL_X_INC, 2 );
				GF_BGL_ScrollSet( wk->bgl, INTRO_PPL1_S_FRAME, GF_BGL_SCROLL_X_INC, 2 );
				GF_BGL_ScrollSet( wk->bgl, INTRO_PPL1_S_FRAME, GF_BGL_SCROLL_Y_SET, y );
			} else {
				FRAME_OFF( INTRO_PPL1_S_FRAME )
				wk->work[7] = 30;
				*seq = 2;
			}
		}
		break;

	case 2:
		if( wk->work[7] ){
			wk->work[7]--;
		} else {
			FRAME_ON( INTRO_PPL2_M_FRAME )
			wk->work[5] = 0;
			wk->work[6] = 9;
			wk->work[7] = 0;
			*seq = 3;
		}
		break;

	case 3:
		{
			int scrx = GF_BGL_ScrollGetX( wk->bgl, INTRO_PPL2_M_FRAME );
			int scry = GF_BGL_ScrollGetY( wk->bgl, INTRO_PPL2_M_FRAME );

			int plus = wk->work[6] * GRABITY_VAL * wk->work[7];
			int minus = GRABITY_VAL * wk->work[7] * wk->work[7] / 2;
			int y = POKE_FSTPOSY + plus - minus;

			if(( wk->work[5] > 0 ) && ( y <= 0 )){
				GF_BGL_ScrollSet( wk->bgl, INTRO_PPL2_M_FRAME, GF_BGL_SCROLL_Y_SET, 0 );
				wk->work[5] = 0;
				wk->work[6] = 1;
				wk->work[7] = 0;
				*seq = 4;
			} else {
				wk->work[7]++;
				wk->work[5] = y;
				GF_BGL_ScrollSet( wk->bgl, INTRO_PPL2_M_FRAME, GF_BGL_SCROLL_X_INC, 1 );
				y = y >> 1;
				if( y > 8*18 ){
					y = 8*18;
				}
				GF_BGL_ScrollSet( wk->bgl, INTRO_PPL2_M_FRAME, GF_BGL_SCROLL_Y_SET, y );
			}
		}
		break;

	case 4:
		{
			int scrx = GF_BGL_ScrollGetX( wk->bgl, INTRO_PPL2_M_FRAME );
			int scry = GF_BGL_ScrollGetY( wk->bgl, INTRO_PPL2_M_FRAME );

			int plus = wk->work[6] * GRABITY_VAL * wk->work[7];
			int minus = GRABITY_VAL * wk->work[7] * wk->work[7] / 2;
			int y = plus - minus;

			if(( wk->work[5] > 0 ) && ( y <= 0 )){
				GF_BGL_ScrollSet( wk->bgl, INTRO_PPL2_M_FRAME, GF_BGL_SCROLL_Y_SET, 0 );
				*seq = 5;
			} else {
				wk->work[7]++;
				GF_BGL_ScrollSet( wk->bgl, INTRO_PPL2_M_FRAME, GF_BGL_SCROLL_X_INC, 2 );
				GF_BGL_ScrollSet( wk->bgl, INTRO_PPL2_M_FRAME, GF_BGL_SCROLL_Y_SET, y );
				wk->work[5] = y;
			}
		}
		break;

	case 5:
		//PLATINUM_MERGE form指定追加(シェイミスカイフォルムじゃないので0でいい)
		Snd_PMVoicePlay( INTRO_MONSNO , 0);

		Intro_BGscrPalChange( wk, INTRO_PPL2_M_FRAME, INTRO_PPL2PLT_M_NUM );
		result = TRUE;
		break;
	}
	return result;
}

static void Intro_PokeScrollEnd( INTRO_DEMO_WORK * wk )
{
	GF_BGL_PrioritySet( INTRO_PPL2_M_FRAME, 1 );
}





//----------------------------------
//
//
//
//
//シーケンス
//
//
//
//
//----------------------------------
#define SUBSEQ_RESET			{ wk->subseq = 0; }
#define SUBSEQ_SET( seq )		{ wk->subseq = seq; }
#define SUBNEXTSEQ_SET( seq, seqnext )	{	\
	wk->subnextseq = seqnext;				\
	wk->subseq = seq;						\
}
#define SUBNEXTSEQ_LOAD			{ wk->subseq = wk->subnextseq; }



#define FRAME_SCROLL_SET( frame, val )	\
	{ GF_BGL_ScrollSet( wk->bgl, frame, GF_BGL_SCROLL_X_SET, val ); }

#define INTRO_FLUSH_SET( sync, to, from  )	{											\
	ChangeBrightnessRequest( sync, to, from,											\
		( GX_BLEND_PLANEMASK_BG0 | GX_BLEND_PLANEMASK_BG1 | GX_BLEND_PLANEMASK_BG3 | GX_BLEND_PLANEMASK_OBJ ),	\
		MASK_MAIN_DISPLAY );															\
	ChangeBrightnessRequest( sync, to, from,											\
		( GX_BLEND_PLANEMASK_BG0 | GX_BLEND_PLANEMASK_BG2 | GX_BLEND_PLANEMASK_BG3 | GX_BLEND_PLANEMASK_OBJ ),	\
		MASK_SUB_DISPLAY );																\
}

#define INTRO_FLUSH_WAIT	( (IsFinishedBrightnessChg( MASK_MAIN_DISPLAY ) == TRUE )	\
							  &&(IsFinishedBrightnessChg( MASK_SUB_DISPLAY ) == TRUE ) )

enum{
	SEQ_0_0_00 = 0, SEQ_0_0_01, SEQ_0_0_02, SEQ_0_0_03,SEQ_0_0_04,SEQ_0_0_05,SEQ_0_0_06,SEQ_0_0_00_1,
//	SEQ_0_1_00, SEQ_0_1_01, SEQ_0_1_02, SEQ_0_1_03,
//	SEQ_0_2_00, SEQ_0_2_01, SEQ_0_2_02, SEQ_0_2_03,
//	SEQ_0_3_00, SEQ_0_3_01, SEQ_0_3_02, SEQ_0_3_03,
//	SEQ_0_4_00, SEQ_0_4_01, SEQ_0_4_02, SEQ_0_4_03,
//	SEQ_0_5_00, SEQ_0_5_01, SEQ_0_5_02, SEQ_0_5_03,
//	SEQ_0_6_00, SEQ_0_6_01, SEQ_0_6_02, SEQ_0_6_03,
//	SEQ_1_1_00,
//	SEQ_1_2_00, SEQ_1_2_01,
//	SEQ_1_3_00,
//	SEQ_1_4_00, SEQ_1_4_01, SEQ_1_4_02, SEQ_1_4_03,
	SEQ_2_1_00, SEQ_2_1_01, SEQ_2_1_02, SEQ_2_1_03, SEQ_2_1_04, SEQ_2_1_05,
	SEQ_2_2_00,
	SEQ_2_4_00, SEQ_2_4_01,
	SEQ_2_5_00, SEQ_2_5_01, SEQ_2_5_02, SEQ_2_5_03, SEQ_2_5_04,
	SEQ_2_6_00,	SEQ_2_6_01,	SEQ_2_6_02,	SEQ_2_6_03,	SEQ_2_6_04,	SEQ_2_6_05,	SEQ_2_6_06,	SEQ_2_6_07,
	SEQ_2_7_00,	SEQ_2_7_01,	SEQ_2_7_02,	SEQ_2_7_03,
	SEQ_3_1_00, SEQ_3_1_01, SEQ_3_1_02,	SEQ_3_1_03, SEQ_3_1_04, SEQ_3_1_05,SEQ_3_1_06, SEQ_3_1_07, SEQ_3_1_08, SEQ_3_1_09,
	SEQ_4_0_00,	SEQ_4_0_01,
	SEQ_4_1_00, SEQ_4_1_01, SEQ_4_1_02, SEQ_4_1_03, SEQ_4_1_04,
				SEQ_4_1_05, SEQ_4_1_06, SEQ_4_1_07, SEQ_4_1_08, SEQ_4_1_09,SEQ_4_1_10,SEQ_4_1_11,SEQ_4_1_12,SEQ_4_1_13,
	SEQ_5_1_00, SEQ_5_1_01, SEQ_5_1_02, SEQ_5_1_03, SEQ_5_1_04, SEQ_5_1_05,
				SEQ_5_1_06, SEQ_5_1_07, SEQ_5_1_07_01, SEQ_5_1_08,  SEQ_5_1_09, SEQ_5_1_10, SEQ_5_1_11,
	SEQ_5_2_00, SEQ_5_2_01, SEQ_5_2_02, SEQ_5_2_03, SEQ_5_2_04, SEQ_5_2_05,
	SEQ_5_3_00,
	SEQ_5_4_00, SEQ_5_4_01, SEQ_5_4_02, SEQ_5_4_03,
	SEQ_5_5_00, SEQ_5_5_01,
	SEQ_5_6_00, SEQ_5_6_01,
	SEQ_5_7_00,	SEQ_5_7_01, SEQ_5_7_02, SEQ_5_7_03, SEQ_5_7_04,
	SEQ_6_0_00, SEQ_6_0_01,
	SEQ_6_1_00, SEQ_6_1_01, SEQ_6_1_02, SEQ_6_1_03, SEQ_6_1_04,
	SEQ_7_1_00, SEQ_7_1_01, SEQ_7_1_02, SEQ_7_1_03,
	SEQ_7_2_00,	SEQ_7_2_01,	SEQ_7_2_02,
	SEQ_7_3_00, SEQ_7_3_01, SEQ_7_3_02,
	SEQ_8_1_00, SEQ_8_1_01, SEQ_8_1_02, SEQ_8_1_03,
	SEQ_8_2_00, SEQ_8_2_01, SEQ_8_2_02, SEQ_8_2_03, SEQ_8_2_04, SEQ_8_2_05,
	SEQ_9_1_00, SEQ_9_1_01, SEQ_9_1_02,
	SEQ_9_2_00, SEQ_9_2_01, SEQ_9_2_02, SEQ_9_2_03, SEQ_9_2_04, SEQ_9_2_05,
};



//------------------------------------------------------------------
/**
 * @brief   金銀イントロ画面
 *
 * @param   wk
 *
 * @retval  int		TRUEでイントロ終了
 */
//------------------------------------------------------------------
static BOOL Intro_GSSeq( INTRO_DEMO_WORK * wk )
{
	BOOL result = FALSE;

#ifdef PM_DEBUG
#ifdef DEBUG_ONLY_FOR_genya_hosaka
	if( sys.cont & PAD_BUTTON_DEBUG )
	{
		return TRUE;
	}
#endif
#endif

	switch(wk->subseq){
	case SEQ_0_0_00:
		FRAME_OFF( INTRO_PBTN_S_FRAME )	// 下画面ボタン面
		//PLAYER_BGMでタイトル、オープニングを鳴らすようにする
		Snd_DataSetByScene( SND_SCENE_OPENING, SEQ_GS_POKEMON_THEME, 1 );	//オープニング曲再生
		Snd_BgmStop( SEQ_GS_POKEMON_THEME, 0 );
		Snd_BgmPlay( SEQ_GS_STARTING );
		SUBSEQ_SET( SEQ_0_0_00_1 )
		break;

	case SEQ_0_0_00_1:
		Intro_GraphicLoadSceneBTN( wk, BGTYPE_SUBBTN_3 );
		Intro_GraphicLoadSceneM( wk, BGTYPE_MAIN_TUTORIAL0 );
		Intro_GraphicLoadSceneS( wk, BGTYPE_SUB_NULL );

		FRAME_ON( INTRO_BACK_M_FRAME )	// 上画面背景
		FRAME_ON( INTRO_TEXT_M_FRAME )	// 上画面文字面
		FRAME_ON( INTRO_TEXT_S_FRAME )	// 下画面文字面
		FRAME_ON( INTRO_BACK_S_FRAME )	// 下画面背景
		//WIPE_ResetBrightness( WIPE_DISP_MAIN );
		//WIPE_ResetBrightness( WIPE_DISP_SUB );

		FADE( WIPE_TYPE_FADEIN, WIPE_FADE_BLACK, wk->heapID )
		SUBSEQ_SET( SEQ_0_0_01 )
		break;

	case SEQ_0_0_01:
		if(WIPE_SYS_EndCheck() == TRUE){
			if( Intro_Wait( wk, 40 ) == TRUE ){
				SUBSEQ_SET( SEQ_0_0_02 )
			}
		}
		break;

//----------------------------------

	// 「いろいろなことをせつめいします」
	case SEQ_0_0_02:
		if( Intro_GuidePrint2( wk, msg_operation_00_00, GUIDETYPE_EXPLAIN ) == TRUE ){
			FRAME_ON( INTRO_PBTN_S_FRAME )	// 下画面ボタン面
			SUBSEQ_SET( SEQ_0_0_03 )
			Intro_ButtonMsgPrint( wk, msg_opening_21, msg_opening_22, msg_opening_23, 3 );

			// カーソルは表示していない事にする
			wk->cursor.on = 0;
			// 座標初期化
			wk->cursor.pos = 0;
		}
		break;

	// ３択待ち開始
	case SEQ_0_0_03:
		if(Intro_ButtonMain( wk, BTNTYPE_3 )!=-1){
			SUBSEQ_SET( SEQ_0_0_04 )
//			wk->cursor.waitmax = 4;
		}
		break;

	// 説明文消えるのを待つ
	case SEQ_0_0_04:
		if( Intro_GuidePrint( wk, msg_operation_00_00, GUIDETYPE_EXPLAIN, 5, 18 ) == TRUE ){
			Intro_ButtonMsgDel( wk );
			FRAME_OFF( INTRO_TEXT_S_FRAME )	// 下画面文字面
			FRAME_OFF( INTRO_PBTN_S_FRAME )	// 下画面ボタン面
			FRAME_OFF( INTRO_PPL1_S_FRAME )	// 下画面ボタン面

			SUBSEQ_SET( SEQ_0_0_05 )
		}
		break;
	case SEQ_0_0_05:
		FADE( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID )
		SUBSEQ_SET( SEQ_0_0_06 )

		break;
	case SEQ_0_0_06:
		if(WIPE_SYS_EndCheck() == TRUE){
			switch(wk->cursor.pos){
			// 操作説明
			case 0:
				SUBSEQ_SET( SEQ_2_1_00 )
				break;
			// ぼうけんとは
			case 1:
				SUBSEQ_SET( SEQ_3_1_00 )
				break;
			// オーキド登場
			case 2:
				SUBSEQ_SET( SEQ_4_0_00 )
				break;
			}
		}
		break;

//----------------------------------
	case SEQ_2_1_00:
		// メイン画面背景設定(操作方法説明開始）
		GF_BGL_ScrClear( wk->bgl, INTRO_TEXT_S_FRAME );

		Intro_GraphicLoadSceneM( wk, BGTYPE_MAIN_TUTORIAL0 );
		Intro_GraphicLoadSceneS( wk, BGTYPE_SUB_TUTORIALBALL );

		Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_ENABLE );

		FRAME_ON( INTRO_TEXT_S_FRAME )	// 下画面テキスト面
		FRAME_ON( INTRO_BACK_S_FRAME )	// 下画面ボタン面

		FADE( WIPE_TYPE_FADEIN, WIPE_FADE_BLACK, wk->heapID )
		SUBSEQ_SET( SEQ_2_1_01 )
		break;

	// フェード待ち
	case SEQ_2_1_01:
		if(WIPE_SYS_EndCheck() == TRUE){
			SUBSEQ_SET( SEQ_2_1_03 )
		}
		break;

#if 0
	// ポケットモンスター きんぎん　の
	case SEQ_2_1_02:
		if( Intro_GuidePrint2( wk, msg_operation_00_01, GUIDETYPE_OPERA ) == TRUE ){
			SUBSEQ_SET( SEQ_2_1_03 )
		}
		break;
#endif

	// ポケットモンスター　きんぎん　では
	case SEQ_2_1_03:
		if( Intro_GuidePrint2( wk, msg_operation_00_02, GUIDETYPE_OPERA ) == TRUE ){
			SUBSEQ_SET( SEQ_2_1_04 )
		}
		break;

	// このように　がめんをタッチ　することで
	case SEQ_2_1_04:
		if( Intro_GuidePrint2( wk, msg_operation_01_00, GUIDETYPE_OPERA ) == TRUE ){
			SUBSEQ_SET( SEQ_2_1_05 )
		}
		break;

	// また　「Ａ」と　かかれている　ものは　そのボタンでも
	case SEQ_2_1_05:
		if( Intro_GuidePrint2( wk, msg_operation_01_01, GUIDETYPE_OPERA ) == TRUE ){
			SUBSEQ_SET( SEQ_2_2_00 )
		}
		break;

//----------------------------------

	// タッチスクリーンには　そのばめんに　あわせて
	case SEQ_2_2_00:
		if( Intro_GuidePrint2( wk, msg_operation_02_00, GUIDETYPE_OPERA ) == TRUE ){
			SUBSEQ_SET( SEQ_2_4_00 )
		}
		break;

//----------------------------------
	// タッチスクリーン使用時のメッセージウインドウについて
	case SEQ_2_4_00:
		// GUIDETYPE_EXPLAIN は内部シーケンスの途中でTRUEが帰り、次回同関数を呼んだタイミングでシーケンスが進むので注意
		if( Intro_GuidePrint2( wk, msg_operation_04, GUIDETYPE_EXPLAIN ) == TRUE ){
			FRAME_ON( INTRO_TEXT_M_FRAME )
			SUBSEQ_SET( SEQ_2_4_01 )
		}
		break;

	case SEQ_2_4_01:
		if( Intro_MsgPrint( wk, msg_opening_35, A_BUTTON_WAIT ) == TRUE ){
//			FRAME_OFF( INTRO_TEXT_M_FRAME )
			SUBSEQ_SET( SEQ_2_5_00 )
		}
		break;

//----------------------------------

	case SEQ_2_5_00:
		// タッチスクリーンに　ボタンが
		if( Intro_GuidePrint2( wk, msg_operation_04_00, GUIDETYPE_OPERA ) == TRUE ){
			// メイン画面背景設定
			Intro_GraphicLoadSceneM( wk, BGTYPE_MAIN_TUTORIAL1 );
//			FRAME_ON( INTRO_BACK_S_FRAME )
			SUBSEQ_SET( SEQ_2_5_01 )
		}
		break;

	// 十字キー説明
	case SEQ_2_5_01:
		// じょうげ　さゆうに
		if( Intro_GuidePrint2( wk, msg_operation_04_01, GUIDETYPE_OPERA_L ) == TRUE ){
			// メイン画面背景設定
			Intro_GraphicLoadSceneM( wk, BGTYPE_MAIN_TUTORIAL0 );
			SUBSEQ_SET( SEQ_2_5_02 )
		}
		break;

	// ABボタン説明
	case SEQ_2_5_02:
		// また　タッチを　つかわずに　ボタン
		if( Intro_GuidePrint2( wk, msg_operation_05_00, GUIDETYPE_OPERA ) == TRUE ){
			// メイン画面背景設定
			Intro_GraphicLoadSceneM( wk, BGTYPE_MAIN_TUTORIAL2 );
			SUBSEQ_SET( SEQ_2_5_03 )
		}
		break;

	case SEQ_2_5_03:
		// けっていする　しらべる　はなす
		if( Intro_GuidePrint2( wk, msg_operation_05_01, GUIDETYPE_OPERA_L ) == TRUE ){
			// メイン画面背景設定
			Intro_GraphicLoadSceneM( wk, BGTYPE_MAIN_TUTORIAL3 );
			SUBSEQ_SET( SEQ_2_5_04 )
		}
		break;

	// XYボタン説明
	case SEQ_2_5_04:
		if( Intro_GuidePrint2( wk, msg_operation_06_00, GUIDETYPE_OPERA_L ) == TRUE ){
			SUBSEQ_SET( SEQ_2_6_00 )
			FRAME_ON( INTRO_TEXT_M_FRAME )
			Intro_GraphicLoadSceneM( wk, BGTYPE_MAIN_TUTORIAL0 );
		}
		break;


//----------------------------------

	// 「ここまでのせつめいはわかりましたか？」
	case SEQ_2_6_00:
		if( Intro_MsgPrint( wk, msg_opening_03, A_BUTTON_NOWAIT ) == TRUE ){
			SUBSEQ_SET( SEQ_2_6_01 )
		}
		break;


	// はい・いいえ 初期化
	case SEQ_2_6_01:
		Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_DISABLE );
		GF_BGL_ScrClear( wk->bgl, INTRO_TEXT_S_FRAME );
		LargeYesno_LoadScreen( wk->p_yesno, INTRO_BTNBALLPLT_S_NUM );
		LargeYesno_Req( wk->p_yesno, NARC_msg_intro_dat, msg_yes, msg_no );
		SUBSEQ_SET( SEQ_2_6_02 )
		break;

	case SEQ_2_6_02:
		switch( LargeYesno_ChcekInputProc( wk->p_yesno ) )
		{
			case LARGE_YESNO_YES :
				SUBSEQ_SET( SEQ_2_6_05 )
				break;
			case LARGE_YESNO_NO :
				SUBSEQ_SET( SEQ_2_6_07 )
				break;
		}
		break;

	// はいを選んだ
	case SEQ_2_6_05:
		if( Intro_AlphaFade( wk, INTRO_PBTN_S_FRAME, ALPHA_FADEOUT ) == TRUE ){
			FADE( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID )
			SUBSEQ_SET( SEQ_2_6_06 )
		}
		break;

	// 冒頭３択へ
	case SEQ_2_6_06:
		if(WIPE_SYS_EndCheck() == TRUE){
			_intro_text_frame_clear( wk );
			SUBSEQ_SET( SEQ_0_0_00_1 )
		}
		break;

	// いいえを選んだ
	case SEQ_2_6_07:
		if( Intro_AlphaFade( wk, INTRO_PBTN_S_FRAME, ALPHA_FADEOUT ) == TRUE ){
			Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_RESET );
			FRAME_OFF( INTRO_PBTN_S_FRAME )
			_intro_text_frame_clear( wk );
			SUBSEQ_SET( SEQ_2_1_00 )
		}
		break;




//----------------------------------
// 冒険とは
	case SEQ_3_1_00:
		// メイン画面背景設定
		Intro_GraphicLoadSceneM( wk, BGTYPE_MAIN_GUIDE );
		Intro_GraphicLoadSceneS( wk, BGTYPE_SUB_GUIDEBALL );

		_intro_text_frame_clear( wk );
		Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_ENABLE );

		FRAME_ON( INTRO_TEXT_S_FRAME )	// 下画面テキスト面
		FRAME_ON( INTRO_BACK_S_FRAME )	// 下画面ボタン面

		FADE( WIPE_TYPE_FADEIN, WIPE_FADE_BLACK, wk->heapID )
		SUBSEQ_SET( SEQ_3_1_01 )
		break;

	case SEQ_3_1_01:
		if(WIPE_SYS_EndCheck() == TRUE){
			SUBSEQ_SET( SEQ_3_1_02 )
		}
		break;

	case SEQ_3_1_02:
		if( Intro_GuidePrint( wk, msg_guide_01, GUIDETYPE_GUIDE, 9, 6 ) == TRUE ){
			SUBSEQ_SET( SEQ_3_1_03 )
		}
		break;

	case SEQ_3_1_03:
		if( Intro_GuidePrint( wk, msg_guide_02, GUIDETYPE_GUIDE, 8, 8 ) == TRUE ){
			SUBSEQ_SET( SEQ_3_1_04 )
		}
		break;

	case SEQ_3_1_04:
		if( Intro_GuidePrint( wk, msg_guide_03, GUIDETYPE_GUIDE, 9, 6 ) == TRUE ){
			SUBSEQ_SET( SEQ_3_1_05 )
		}
		break;

	case SEQ_3_1_05:
		if( Intro_GuidePrint( wk, msg_guide_04, GUIDETYPE_GUIDE, 5, 14 ) == TRUE ){
			SUBSEQ_SET( SEQ_3_1_06 )
		}
		break;

	case SEQ_3_1_06:
		if( Intro_GuidePrint( wk, msg_guide_05, GUIDETYPE_GUIDE, 10, 4 ) == TRUE ){
			SUBSEQ_SET( SEQ_3_1_07 )
		}
		break;

	case SEQ_3_1_07:
		if( Intro_GuidePrint( wk, msg_guide_06, GUIDETYPE_GUIDE, 6, 12 ) == TRUE ){
			SUBSEQ_SET( SEQ_3_1_08 )
		}
		break;

	case SEQ_3_1_08:
		FADE( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID )
		SUBSEQ_SET( SEQ_3_1_09 )
		break;

	// 冒頭へ
	case SEQ_3_1_09:
		if(WIPE_SYS_EndCheck() == TRUE){
			_intro_text_frame_clear( wk );
			Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_DISABLE );
			FRAME_ON( INTRO_TEXT_M_FRAME )
			SUBSEQ_SET( SEQ_0_0_00_1 )
		}
		break;


//----------------------------------
//----------------------------------

	// 寝過ごしメッセージ表示準備
	case SEQ_4_0_00:
		_intro_text_frame_clear( wk );
		Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_ENABLE );
		Intro_GraphicLoadSceneM( wk, BGTYPE_MAIN_NULL );
		GF_BGL_ScrClear( wk->bgl, INTRO_PPL1_S_FRAME );
		FRAME_ON( INTRO_TEXT_M_FRAME )
		FRAME_OFF( INTRO_BACK_M_FRAME )
		FRAME_ON( INTRO_TEXT_S_FRAME )	// 下画面テキスト面
		FRAME_ON( INTRO_BACK_S_FRAME )	// 下画面ボタン面
		SUBSEQ_SET( SEQ_4_0_01 )
		FADE( WIPE_TYPE_FADEIN, WIPE_FADE_BLACK, wk->heapID )
		break;

	case SEQ_4_0_01:
		if(WIPE_SYS_EndCheck() == TRUE){
			if( Intro_Wait( wk, 40 ) == TRUE ){
				SUBSEQ_SET( SEQ_4_1_00 )

				// 時間帯によってオーキドのメッセージを変える
				wk->opening_msg = Intro_OhkidoMsgSet();
			}
		}
		break;

	// オーキド寝過ごした！
	case SEQ_4_1_00:
		if( Intro_MsgPrint( wk, wk->opening_msg, A_BUTTON_NOWAIT ) == TRUE ){
			// BGMフェード
			Snd_BgmFadeOut( 0, INTRO_BGM_FADE_OUT_SYNC );
			SUBSEQ_SET( SEQ_4_1_01 )
		}
		break;

//----------------------------------

	// オーキド登場
	case SEQ_4_1_01:
		// BGMフェードが終了していなければ処理に入らない
		if( Snd_FadeCheck() ) { break; }

//		Snd_BgmPlay( SEQ_OPENING );
		Snd_BgmStop( SEQ_GS_STARTING, 0 );
		Snd_BgmPlay( SEQ_GS_STARTING2 );

		Intro_GraphicLoadScenePPL( wk, BGTYPE_MPPL_DOCTOR, BGTYPE_MPPL_NULL );
		FRAME_ON( INTRO_BACK_M_FRAME )
		FRAME_ON( INTRO_PPL1_M_FRAME )
		// テキストウィンドウ以外にブライドネス
		ChangeBrightnessRequest( 16, BRIGHTNESS_NORMAL, BRIGHTNESS_BLACK,
				( GX_BLEND_PLANEMASK_BG1 | GX_BLEND_PLANEMASK_BG3 | GX_BLEND_PLANEMASK_OBJ ), MASK_MAIN_DISPLAY );
//		WIPE_SYS_Start(	WIPE_PATTERN_M, WIPE_TYPE_FADEIN, WIPE_TYPE_FADEIN, WIPE_FADE_BLACK,
//						16, 4, wk->heapID );
		SUBSEQ_SET( SEQ_4_1_02 )
		break;

	case SEQ_4_1_02:
		if( IsFinishedBrightnessChg(MASK_MAIN_DISPLAY) ) {
//		if(WIPE_SYS_EndCheck() == TRUE){
			SUBSEQ_SET( SEQ_4_1_03 )
		}
		break;


	// わしがポケモンについておしえよう
	case SEQ_4_1_03:
		if( Intro_MsgPrint( wk, msg_opening_02, A_BUTTON_NOWAIT ) == TRUE ){
			SUBSEQ_SET( SEQ_4_1_04 )
		}
		break;

	// はかせが右に移動
	case SEQ_4_1_04:
		if(Intro_BgMove( wk, INTRO_PPL1_M_FRAME, MOVE_TYPE_CENTER_RIGHT)==TRUE){
			SUBSEQ_SET( SEQ_4_1_05)
		}
		break;

	// ポケットモンスター……ポケモン  このせかいには
	case SEQ_4_1_05:
		if( Intro_MsgPrint( wk, msg_opening_06, A_BUTTON_NOWAIT ) == TRUE ){
			// ボール出現
			CLACT_AnmChg( wk->awp[INTRO_OBJ_MARIRU], 3 );
			CLACT_PaletteNoChg( wk->awp[INTRO_OBJ_MARIRU], 5 );
			CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_MARIRU], 1 );
			SUBSEQ_SET( SEQ_4_1_06 )
		}
		break;

	case SEQ_4_1_06:
		if( Intro_Wait( wk, 30 ) == TRUE )
		{
			// 出現エフェクト
			INTRO_FLUSH_SET( 4, BRIGHTNESS_NORMAL, BRIGHTNESS_WHITE )
			//
			Snd_SePlay( SEQ_SE_DP_BOWA2 );
			wk->work[0] = 0;
			SUBSEQ_SET( SEQ_4_1_07 )
		}
		break;

	case SEQ_4_1_07:
//		Intro_PokeScroll( wk, &wk->work[0] );
		if( INTRO_FLUSH_WAIT ){
			// マリル登場アニメ開始
			CLACT_AnmChg( wk->awp[INTRO_OBJ_MARIRU], 1 );
			CLACT_PaletteNoChg( wk->awp[INTRO_OBJ_MARIRU], 4 );
			// マリルをブライドネスで白く
			wk->work[0] = 16;
			G2_SetBlendBrightness( GX_BLEND_PLANEMASK_OBJ, wk->work[0] );

			SUBSEQ_SET( SEQ_4_1_08 )
		}
		break;

	case SEQ_4_1_08:
		if( CLACT_AnmActiveCheck( wk->awp[INTRO_OBJ_MARIRU] ) ) { break; }

//		if( Intro_PokeScroll( wk, &wk->work[0] ) == TRUE )
		// ブライドネスを解除していく
		G2_SetBlendBrightness( GX_BLEND_PLANEMASK_OBJ, --wk->work[0] );
		if( wk->work[0] == 0 ) {
			// 待機アニメ
			CLACT_AnmChg( wk->awp[INTRO_OBJ_MARIRU], 2 );
			// 鳴き声
			Snd_PMVoicePlay( INTRO_MONSNO , 0);
			SUBSEQ_SET( SEQ_4_1_09 )
		}
		break;

	case SEQ_4_1_09:
		if( Intro_Wait( wk, 40 ) == TRUE ){
			SUBSEQ_SET( SEQ_4_1_10 )
		}
		break;

	// われわれにんげんは　ポケモンとなかよく…
	case SEQ_4_1_10:
		if( Intro_MsgPrint( wk, msg_opening_09, A_BUTTON_NOWAIT ) == TRUE ){
			SUBSEQ_SET( SEQ_4_1_11 )
		}
		break;

	// ポケモン消える
	case SEQ_4_1_11:
		if( Intro_AlphaFade( wk, ALPHA_FRAME_OBJ_M, ALPHA_FADEOUT ) == TRUE ){
//			Intro_PokeScrollEnd( wk );
			SUBSEQ_SET( SEQ_4_1_12 )
		}
		break;

	case SEQ_4_1_12:
		if( Intro_Wait( wk, 30 ) == TRUE ){
			SUBSEQ_SET( SEQ_4_1_13 )
		}
		break;
	case SEQ_4_1_13:
		if(Intro_BgMove( wk, INTRO_PPL1_M_FRAME, MOVE_TYPE_RIGHT_CENTER)==TRUE){
			SUBSEQ_SET( SEQ_5_1_00)
		}

		break;

//----------------------------------

	// さてそろそろきみのことをおしえてもらおう
	case SEQ_5_1_00:
		if( Intro_MsgPrint( wk, msg_opening_36, A_BUTTON_NOWAIT ) == TRUE ){
			SUBSEQ_SET( SEQ_5_1_01 )
			wk->cursor.pos = 0;
			wk->cursor.max = 2;
		}
		break;
	case SEQ_5_1_01:
		if( Intro_MsgPrint( wk, msg_opening_10, A_BUTTON_NOWAIT ) == TRUE ){
			SUBSEQ_SET( SEQ_5_1_02 )
			FADE_SUBONLY( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID )
		}
		break;
	case SEQ_5_1_02:
		if(WIPE_SYS_EndCheck() == TRUE){
			SUBSEQ_SET( SEQ_5_1_03 )
		}
		break;

	// 下画面に男の子と女の子登場
	case SEQ_5_1_03:
		Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_DISABLE );
		FRAME_OFF( INTRO_TEXT_S_FRAME )

		Intro_GraphicLoadSceneS( wk, BGTYPE_SUB_SEXSELECT );
		Intro_HeroHeroineVisible( wk, BOTH_ON );
		GF_BGL_ScrClear( wk->bgl, INTRO_PBTN_S_FRAME );
		FADE_SUBONLY( WIPE_TYPE_FADEIN, WIPE_FADE_BLACK, wk->heapID )

		SUBSEQ_SET( SEQ_5_1_04 )
		break;
	case SEQ_5_1_04:
		if(WIPE_SYS_EndCheck() == TRUE){
			wk->cursor.pos = wk->gender_work;
			SUBSEQ_SET( SEQ_5_1_05 )
		}
		break;

	// 選択待ち
	case SEQ_5_1_05:
		if(Intro_SelectSex( wk )){
			SUBSEQ_SET( SEQ_5_1_06 )
			wk->mysex = wk->cursor.pos;
		}
		break;

	// 選択されなかった方のBGをクリアする
	case SEQ_5_1_06:
		GF_BGL_ScrFill(	wk->bgl, INTRO_BACK_S_FRAME, 1, (wk->cursor.pos^1)*16, 0, 16, 23, 0 );
		GF_BGL_LoadScreenReq( wk->bgl,  INTRO_PBTN_S_FRAME);
		GF_BGL_LoadScreenReq( wk->bgl,  INTRO_BACK_S_FRAME);

		GF_BGL_ScrClear( wk->bgl, INTRO_TEXT_S_FRAME );

		// 選択されなかったほうの主人公を消す
		Intro_HeroHeroineVisible( wk, wk->mysex );

		// 男女メッセージ分岐
		if(wk->mysex==PM_MALE){
			wk->opening_msg = msg_opening_11;
		}else{
			wk->opening_msg = msg_opening_12;
		}

		SUBSEQ_SET( SEQ_5_1_07 )
		break;

		// きみは　おとこのこ／おんなのこ　じゃな！？
	case SEQ_5_1_07:
		if( Intro_MsgPrint( wk, wk->opening_msg, A_BUTTON_NOWAIT ) == TRUE ){
			SUBSEQ_SET( SEQ_5_1_07_01 )
		}
		break;

	case SEQ_5_1_07_01:
	// 「はい」「いいえ」の選択肢初期化
		Intro_ButtonInit(&wk->cursor, BTNTYPE_2 );

		// 選択肢の位置を男女によって移動させる
		Intro_GraphicLoadSceneBTN( wk, BGTYPE_SUBBTN_2_TATE );
		Intro_ButtonMsgPrint( wk, msg_opening_24, msg_opening_25, 0, 2 );
		SUBSEQ_SET( SEQ_5_1_08 )
		wk->cursor.pos = 0;
		break;
	case SEQ_5_1_08:
		// 男女によって選択肢の位置が左右に移動する
		FRAME_ON( INTRO_TEXT_S_FRAME )
		FRAME_ON( INTRO_PBTN_S_FRAME )
		if(Intro_ButtonMain( wk, BTNTYPE_2+wk->mysex )!=-1){
			Intro_ButtonMsgDel( wk );
			SUBSEQ_SET( SEQ_5_1_09 )
		}
		break;

	case SEQ_5_1_09:
		switch(wk->cursor.pos){
		// 名前入力へ
		case 0:
//			FADE( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID )
			SUBSEQ_SET( SEQ_6_0_00 )
			break;

		// やめる
		case 1:
			SUBSEQ_SET( SEQ_5_1_10 )
			FADE_SUBONLY( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID )
			break;
		}
		break;

	// やめたら男女選択肢の部分を一旦フェードして戻す
	case SEQ_5_1_10:
		if(WIPE_SYS_EndCheck() == TRUE){
			FRAME_OFF( INTRO_PPL1_S_FRAME )
			FRAME_OFF( INTRO_PBTN_S_FRAME )
			Intro_HeroHeroineVisible( wk, BOTH_OFF );
			Intro_GraphicLoadSceneS( wk, BGTYPE_SUB_TUTORIALBALL );

			GF_BGL_ScrClear( wk->bgl, INTRO_TEXT_S_FRAME );
			GF_BGL_ScrollReq( wk->bgl, INTRO_TEXT_S_FRAME, GF_BGL_SCROLL_X_SET, 0 );

			// 選択パレット初期化
			MaleFmale_NoSelect( wk );

			FADE_SUBONLY( WIPE_TYPE_FADEIN, WIPE_FADE_BLACK, wk->heapID )
			SUBSEQ_SET( SEQ_5_1_11 )
		}
		break;
	// 博士の言葉「おとこのこかな？おんなのこかな？」へ戻る
	case SEQ_5_1_11:
		if(WIPE_SYS_EndCheck() == TRUE){
			Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_ENABLE );
			SUBSEQ_SET( SEQ_5_1_01 )
		}
		break;

//----------------------------------
	// では　なまえを　おしえてくれ！
	case SEQ_6_0_00:
		if( Intro_MsgPrint( wk, msg_opening_13, A_BUTTON_NOWAIT ) == TRUE ){
			SUBSEQ_SET( SEQ_6_0_01 )
		}
		break;
	// ウェイト
	case SEQ_6_0_01:
		if( Intro_Wait( wk, 40 ) )
		{
			SUBSEQ_SET( SEQ_6_1_00 )
		}
		break;
	// 名前入力開始
	case SEQ_6_1_00:
		//BTS241 2回目以降の呼び出しの際、前回の名前が入力されている状態になっているバグ修正nagihashi
		STRBUF_Clear( wk->myname->strbuf );
		wk->myname->info = wk->mysex;
		wk->subproc = PROC_Create( &NameInProcData, wk->myname, wk->heapID );
		SUBSEQ_SET( SEQ_6_1_01 )
		break;

	// 画面再構築
	case SEQ_6_1_01:
		FRAME_ON( INTRO_TEXT_M_FRAME )
		FRAME_ON( INTRO_PPL1_M_FRAME )
		FRAME_ON( INTRO_BACK_M_FRAME )
		FRAME_ON( INTRO_TEXT_S_FRAME )
		FRAME_ON( INTRO_BACK_S_FRAME )
		FRAME_ON( INTRO_PBTN_S_FRAME )
		FRAME_SCROLL_SET( INTRO_PPL1_M_FRAME, 0 )
		NameDecideBgSet( wk );
		FADE( WIPE_TYPE_FADEIN, WIPE_FADE_BLACK, wk->heapID )
		SUBSEQ_SET( SEQ_6_1_02 )
		Intro_GraphicLoadScenePPL( wk, BGTYPE_MPPL_DOCTOR, BGTYPE_MPPL_NULL );
		Intro_HeroHeroineVisible( wk, wk->mysex );

		if(wk->mysex==PM_MALE){
			wk->opening_msg = msg_opening_14;
		}else{
			wk->opening_msg = msg_opening_15;
		}
		break;

	// ●●●じゃな？
	case SEQ_6_1_02:
		if( Intro_MsgPrint( wk, wk->opening_msg, A_BUTTON_NOWAIT ) == TRUE ){
			SUBSEQ_SET( SEQ_6_1_03 )
			Intro_ButtonInit(&wk->cursor, BTNTYPE_2 );
		}
		break;

	case SEQ_6_1_03:
		if(Intro_ButtonMain( wk, BTNTYPE_2+wk->mysex )!=-1){
			Intro_ButtonMsgDel( wk );
			SUBSEQ_SET( SEQ_6_1_04 )
		}
		break;
	case SEQ_6_1_04:
		switch(wk->cursor.pos){
		// はい
		case 0:
			SUBSEQ_SET( SEQ_7_1_00 )
			break;

		// いいえ
		case 1:
			FADE_SUBONLY( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID )
			SUBSEQ_SET( SEQ_5_1_10 )
			break;
		}
		break;

// -------------------------------------

	// ではまたあおう！
	case SEQ_7_1_00:
		FADE_SUBONLY( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID )
		SUBSEQ_SET( SEQ_7_1_01 )
		break;
	case SEQ_7_1_01:
		if(WIPE_SYS_EndCheck() == TRUE){
			FRAME_OFF( INTRO_PBTN_S_FRAME )
			FRAME_OFF( INTRO_PPL1_S_FRAME )
			Intro_GraphicLoadSceneS( wk, BGTYPE_SUB_TUTORIALBALL );
			Intro_HeroHeroineVisible( wk, BOTH_OFF );

			GF_BGL_ScrClear( wk->bgl, INTRO_TEXT_S_FRAME );
			GF_BGL_ScrollReq( wk->bgl, INTRO_TEXT_S_FRAME, GF_BGL_SCROLL_X_SET, 0 );

			Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_ENABLE );

			FADE_SUBONLY( WIPE_TYPE_FADEIN, WIPE_FADE_BLACK, wk->heapID )

			SUBSEQ_SET( SEQ_7_1_02 )
		}
		break;
	case SEQ_7_1_02:
		if(WIPE_SYS_EndCheck() == TRUE){
			SUBSEQ_SET( SEQ_7_1_03 )
		}
		break;

	// さあポケモンのせかいへ！
	case SEQ_7_1_03:
		if( Intro_MsgPrint( wk, msg_opening_19, A_BUTTON_NOWAIT ) == TRUE ){
			SUBSEQ_SET( SEQ_8_1_00 )
		}
		break;
	case SEQ_8_1_00:
		FADE( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID );
		SUBSEQ_SET( SEQ_8_1_01 )
		break;
	case SEQ_8_1_01:
		if(WIPE_SYS_EndCheck() == TRUE){
			SUBSEQ_SET( SEQ_9_1_00 )
		}
		break;

	// 主人公画像にさしかえ
	case SEQ_9_1_00:
		if( wk->mysex == PM_MALE ){
			Intro_GraphicLoadScenePPL( wk, BGTYPE_MPPL_HERO_0, BGTYPE_MPPL_NULL );
		} else {
			Intro_GraphicLoadScenePPL( wk, BGTYPE_MPPL_HEROINE_0, BGTYPE_MPPL_NULL );
		}
		FADE( WIPE_TYPE_FADEIN, WIPE_FADE_BLACK, wk->heapID )
		SUBSEQ_SET( SEQ_9_1_01 )
		FRAME_OFF( INTRO_TEXT_M_FRAME )
		break;
	case SEQ_9_1_01:
		if(WIPE_SYS_EndCheck() == TRUE){
			SUBSEQ_SET( SEQ_9_2_00 )
		}
	case SEQ_9_2_00:
		SUBSEQ_SET( SEQ_9_2_01 )
		break;

	case SEQ_9_2_01:
		Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_DISABLE );
		Intro_MineAnimeMinInit( wk );
		SUBSEQ_SET( SEQ_9_2_02 )
		break;

	case SEQ_9_2_02:
		if( Intro_Wait( wk, 30 ) == TRUE ){
			Snd_SePlay( SEQ_SE_GS_HERO_SHUKUSHOU );
			SUBSEQ_SET( SEQ_9_2_03 )
		}
		break;

	case SEQ_9_2_03:
		if( Intro_MineMinAnime( wk ) == TRUE ){
//			SUBSEQ_SET( SEQ_10_1_00 )

			// ＴＶ番組を飛ばす

			result = TRUE;

		}
		break;



	}


	return result;
}



//------------------------------------------------------------------
/**
 * @brief   名前入力から復帰した時の下画面構築
 *
 * @param   wk
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void NameDecideBgSet( INTRO_DEMO_WORK *wk )
{
	Intro_GraphicLoadSceneBTN( wk, BGTYPE_SUBBTN_2_TATE );
	Intro_GraphicLoadSceneS( wk, BGTYPE_SUB_SEXSELECT );
	Intro_ButtonMsgPrint( wk, msg_opening_24, msg_opening_25, 0, 2 );

	GF_BGL_ScrFill(	wk->bgl, INTRO_BACK_S_FRAME, 1, (wk->mysex^1)*16, 0, 16, 23, 0 );
	GF_BGL_LoadScreenReq( wk->bgl,  INTRO_BACK_S_FRAME);

}

//------------------------------------------------------------------
/**
 * @brief   テキスト面のクリア
 *
 * @param   wk
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void _intro_text_frame_clear( INTRO_DEMO_WORK *wk )
{
	GF_BGL_ScrClear( wk->bgl, INTRO_TEXT_M_FRAME );
	GF_BGL_ScrClear( wk->bgl, INTRO_TEXT_S_FRAME );

}

//==============================================================================
// タッチボタン
//==============================================================================

//==============================================================================
//==============================================================================
static void _TouchButton_Print( INTRO_DEMO_WORK* wk )
{
	STRBUF* strbuf = STRBUF_Create(INTRO_STRBUF_SIZE, wk->heapID );
	GF_BGL_BMPWIN* win = &wk->msg_touch_button;

	MSGMAN_GetString( wk->msgman, msg_opening_39, strbuf );

	GF_BGL_BmpWinAddEx( wk->bgl, win, &touch_button_msg_windata );
	GF_BGL_BmpWinDataFill( win, 0x0000 );
	GF_STR_PrintColor( win, FONT_TOUCH, strbuf, 0, 0, 0, GF_PRINTCOLOR_MAKE(15,1,0), NULL );
	GF_BGL_BmpWinOn( win );
	GF_BGL_BmpWinDel( win );

	STRBUF_Delete( strbuf );
}

//==============================================================================
//==============================================================================
static void _TouchButton_Clear( INTRO_DEMO_WORK* wk )
{
	GF_BGL_BMPWIN* win = &wk->msg_touch_button;

	GF_BGL_BmpWinAddEx( wk->bgl, win, &touch_button_msg_windata );
	GF_BGL_BmpWinDataFill( win, 0x0000 );
	GF_BGL_BmpWinOn( win );
	GF_BGL_BmpWinDel( win );
}

//==============================================================================
/**
 * @brief	下画面タッチボタンの表示切替
 *
 * @retval	none
 */
//==============================================================================
static void Intro_TouchButtonMode( INTRO_DEMO_WORK* wk, INTRO_BTN_TOUCH_MODE mode )
{
	GF_ASSERT( wk );

	switch( mode )
	{
		case INTRO_BTN_TOUCH_MODE_DISABLE :
			GF_ASSERT( CLACT_GetDrawFlag( wk->awp[INTRO_OBJ_BTN_TOUCH_S] ) == 1 );
			_TouchButton_Clear( wk );
			CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_BTN_TOUCH_S], 0 );
			break;
		case INTRO_BTN_TOUCH_MODE_ENABLE :
			GF_ASSERT( CLACT_GetDrawFlag( wk->awp[INTRO_OBJ_BTN_TOUCH_S] ) == 0 );
			_TouchButton_Print( wk );
			CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_BTN_TOUCH_S], 1 );
			break;
		case INTRO_BTN_TOUCH_MODE_TOUCH :
			CLACT_AnmChg( wk->awp[INTRO_OBJ_BTN_TOUCH_S], 1 );
			break;
		case INTRO_BTN_TOUCH_MODE_RESET :
			CLACT_AnmChg( wk->awp[INTRO_OBJ_BTN_TOUCH_S], 0 );
			break;
		default : GF_ASSERT(0);
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	既にタッチボタンが押されアニメか判定
 *
 *	@param	INTRO_DEMO_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static BOOL Intro_IsTouchButtonPushing( INTRO_DEMO_WORK* wk )
{
	return CLACT_AnmGet( wk->awp[INTRO_OBJ_BTN_TOUCH_S] ) == 1;
}

//-----------------------------------------------------------------------------
/**
 *	@brief
 *
 *	@param	INTRO_DEMO_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static BOOL Intro_GetTouchButtonEnable( INTRO_DEMO_WORK* wk )
{
	GF_ASSERT( wk );
	return ( CLACT_GetDrawFlag( wk->awp[INTRO_OBJ_BTN_TOUCH_S] ) == 1 );
}


//-----------------------------------------------------------------------------
/**
 *	@brief	キー/タッチ入力待ち
 *
 *	@param	INTRO_DEMO_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static BOOL Intro_WaitInput( INTRO_DEMO_WORK* wk, BOOL b_chcek_button )
{
	BOOL b_wait_end = FALSE;

	if( b_chcek_button ) {
		b_wait_end = TRUE;
	}else if( GF_TP_GetCont() ){
		// 多分来ない
		b_wait_end = TRUE;
	}

	if( b_wait_end ) {
		return TRUE;
	}

	return FALSE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	タッチペンでＡボタンをフック
 *
 *	@param	INTRO_DEMO_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void _fuck_touch_to_decide( INTRO_DEMO_WORK* wk )
{
	static const RECT_HIT_TBL btn_touch_tbl[]={
		{ (24-BTN_TOUCH_OBJ_SY)*8,  24*8-1, (32-BTN_TOUCH_OBJ_SX)*8, 32*8-1, },
		{TP_HIT_END,0,0,0},		// 終了データ
	};

	int tp_cont;

	// タッチボタンが有効でなければなにもしない
	if( Intro_GetTouchButtonEnable( wk ) == FALSE )
	{
		return;
	}

	tp_cont = GF_TP_RectHitCont( btn_touch_tbl );

	// 初回
	if( tp_cont == 0 && GF_TP_GetTrg() )
	{
		sys.extra_cont = PAD_BUTTON_A;
		Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_TOUCH );
	}
	// 継続
	else if( tp_cont == 0 && Intro_IsTouchButtonPushing( wk ) )
	{
		sys.extra_cont = PAD_BUTTON_A;
	}
	else
	{
		Intro_TouchButtonMode( wk, INTRO_BTN_TOUCH_MODE_RESET );
	}
}
